簡體   English   中英

Matplotlib標簽y軸

[英]Matplotlib label y axis

我正在嘗試使用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差異。 對此有何解決方案? 謝謝!

嘗試這個:

ax.set_ylim(0.1, 1)
import matplotlib.ticker as tick
ax.yaxis.set_major_locator(tick.MultipleLocator(0.1))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM