Python matplotlib - 设置 x 轴比例 [英] Python matplotlib - setting x-axis scale
本文介绍了Python matplotlib - 设置 x 轴比例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这张图表显示以下内容:
I have this graph displaying the following:
plt.plot(valueX, scoreList)
plt.xlabel("Score number") # Text for X-Axis
plt.ylabel("Score") # Text for Y-Axis
plt.title("Scores for the topic "+progressDisplay.topicName)
plt.show()
valueX = [1, 2, 3, 4] 和scoreList = [5,0,0,2]
valueX = [1, 2, 3, 4] and scoreList = [5, 0, 0, 2]
无论scoreList"中的值是什么,我都希望比例以 1 为单位递增.目前让我的 x 轴在 0.5 秒而不是 1 秒内上升.
I want the scale to go up in 1's, no matter what values are in 'scoreList'. Currently get my x-axis going up in .5 instead of 1s.
如何设置使其仅在 1 中上升?
How do I set it so it goes up only in 1?
推荐答案
只需自行设置xticks.
Just set the xticks yourself.
plt.xticks([1,2,3,4])
或
plt.xticks(valueX)
由于范围函数恰好适用于整数,因此您可以改用它:
Since the range functions happens to work with integers you could use that instead:
plt.xticks(range(1, 5))
或者更具动态性并根据数据进行计算:
Or be even more dynamic and calculate it from the data:
plt.xticks(range(min(valueX), max(valueX)+1))
这篇关于Python matplotlib - 设置 x 轴比例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文