我有以下情節代碼。我希望圖中的最后一個軸不接觸圖形線的邊緣,希望位于圖中紅色所示的中間。
x = np.array([1,2,3,4,5,6,7,8,9])
y=[83.742,83.572,80.446,85.960,85.031,84.605,85.348,86.910,83.572]
z=[83.9901, 83.6721,80.2542,86.2601,84.9232,84.3019,85.4232,86.7565,84.5207]
plt.bar(x-0.2, y, width=0.4,label='Actual', color='g', align='center')
plt.bar(x 0.2, z, width=0.4,label='Predicted', color='b', align='center')
plt.ylim(60,95)
plt.legend(loc=2, prop={'size': 6.5})
labels=[1,2,3,4,5,6,7,8,9,10]
plt.xticks(labels,labels,rotation=60)
str_x = [l for l in labels if not l in x]
for s_x in str_x:
plt.text(s_x, 70, 'x', ha='center', fontsize=16,color='r')
plt.xlabel("Node no")
plt.ylabel("Accuracy (%)")
plt.show()

uj5u.com熱心網友回復:
添加:
plt.xlim([0,11])
您可能需要修改限制。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/342638.html
標籤:Python matplotlib
