我正试图使用matplotlib构建一个图表,但不幸的是,我无法弄清楚如何标注y轴。我想从0.1到1.0开始做这件事,但是有一个0.1的差异。我设法像这样设定了它的极限:
import numpy as np
import matplotlib.pyplot as plt
N = 10
menMeans = (0.58836, 0.6224, 0.73047, 0.79147, 0.79284, 0.79264, 0.79922, 0.82043, 0.81834, 0.74767)
ind = np.arange(N) # the x locations for the groups
width = 0.20 # the width of the bars
fig, ax = plt.subplots()
rects1 = ax.bar(ind, menMeans, width, color='g')
womenMeans = (0.61139, 0.62270, 0.63627, 0.75868, 0.73087, 0.73128, 0.77205, 0.59866, 0.59385, 0.59891)
rects2 = ax.bar(ind+width, womenMeans, width, color='b')
# add some
ax.set_ylabel('Accuracy')
ax.set_xticks(ind+width)
ax.set_xticklabels( ('Naive', 'Norm', 'Unigrams \n(FreqDist)', 'Unigrams(LLR)', 'Unigrams (LLR)\n Bigrams', 'Unigrams (LLR)\n Bigrams (CHI)',
'Unigrams (LLR)\n Bigrams (LLR)', 'Features', 'POS', 'LDA') )
ax.legend( (rects1[0], rects2[0]), ('Naive Bayes', 'Maximum Entropy') )
ax.set_ylim(0, 1)
plt.grid(axis='y', linestyle='-')
plt.show()但是y轴上的数字只有0.2的差。有什么解决办法吗?谢谢!
发布于 2014-01-29 20:38:36
试试这个:
ax.set_ylim(0.1, 1)
import matplotlib.ticker as tick
ax.yaxis.set_major_locator(tick.MultipleLocator(0.1))https://stackoverflow.com/questions/21441976
复制相似问题