我正在尝试使用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差异。对此有何解决方案?谢谢!
答案 0 :(得分:2)
试试这个:
ax.set_ylim(0.1, 1)
import matplotlib.ticker as tick
ax.yaxis.set_major_locator(tick.MultipleLocator(0.1))