我正在尝试用y轴作为文本而不是数字来构建一个线图,我尝试了这个solution但是y轴仍然有数字而不是'text'。我究竟做错了什么。
CurrentCoresLE
是一个字符串列表。
Y_AXIS_VALUES = list(numpy.sort(list(set(CurrentCoresLE))))
Y_AXIS = [Y_AXIS_VALUES.index(CurrentCoresLE[i]) for i in range(len(CurrentCoresLE))]
one = axes4.plot(Y_AXIS, color = '0.2', label='CoresUsed')
axes4.set_ylabel('Cores')
#https://stackoverflow.com/questions/17074772/using-text-on-y-axis-in-matplotlib-instead-of-numbers
#plt.yticks(Y_AXIS, Y_AXIS_VALUES)
axes4.set_yticks(Y_AXIS, Y_AXIS_VALUES)
axes4.legend(prop={'size':6}, ncol=4)
axes4.xaxis.grid(True)
当我尝试plt
代替axes4
时,它确实会提供文字但只有一个地方
这是一个例子:
这是一个例外的Y_AXIS_VALUES和Y_AXIS
['0B2S', '0B3S', '0B4S', '1B3S', '2B0S', '2B2S']
[4, 4, 5, 5, 5, 3, 3, 3, 2, 1, 0, 1, 0, 1, 1, 0, 0, 1, 2, 1, 2, 2, 1, 0, 1, 2, 2, 1, 0, 1, 2, 1, 1, 2, 2, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 3, 3, 3, 2, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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Products = "a:3:{s:8:\"optional\";a:0:{}s:8:\"required\";a:0:{}s:7:\"coupons\";a:0:{}}', 'a:3:{s:19:\"autoInitiateTranfer\";s:1:\"1\";s:17:\"enableNamesuggest\";s:1:\"1\";s:14:\"maxNamesuggest\";s:1:\"5\";}";
$SerializedPricingArray = serialize($PricingArray);
$signup_order = $i + 1;
$SQL_SELECT_Statement = "SELECT * FROM package WHERE planname='" . $json_post['pricestructure']['tld'][$i]['tld'] . "';";
$SQL_UPDATE_Statement = "UPDATE package SET pricing='" . $SerializedPricingArray . "', signup_order=" . $signup_order . " WHERE planid=10 AND planname='" . $json_post['pricestructure']['tld'][$i]['tld'] . "';";
$SQL_INSERT_Statement = "INSERT INTO package (`planname`, `description`, `asset_html`, `highlight`, `planid`, `showpackage`, `pricing`, `style`, `automaticactivation`, `allowdirectlink`, `sendwelcome`, `stockInfo`, `emailTemplate`, `bundledProducts`, `advanced`, `signup_order`) VALUES ('" . $json_post['pricestructure']['tld'][$i]['tld'] . "', '', '', '0', 10, 1, '". $SerializedPricingArray . "', 0, 1, 0, 1, '" . $StockInfo . "', 35, '" . $BundledProducts . "', " . $signup_order . ")";
echo "Working on TLD " . $json_post['pricestructure']['tld'][$i]['tld'] . "\n";
$result = mysqli_query($conn, $SQL_SELECT_Statement);
if (mysqli_num_rows($result) > 0 ) {
echo "Updating " . $json_post['pricestructure']['tld'][$i]['tld'] . " . . . .\n\n";
$result2 = mysqli_query($conn, $SQL_UPDATE_Statement);
} else {
echo "Inserting " . $json_post['pricestructure']['tld'][$i]['tld'] . " . . . .\n\n";
$result2 = mysqli_query($conn, $SQL_INSERT_Statement);
}
我想诀窍是首先设置yticktabels并使用setp