Home > Mobile >  How to set the xticks on the graph
How to set the xticks on the graph

Time:10-30

I have the following code for a plot. I want the last axis in the plot to not touch the edge of the graph line, want to be in the middle as shown in red in the plot.

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()

plot

CodePudding user response:

Add:

plt.xlim([0,11])

You may need to tinker with the limits.

  • Related