我有两张不同价格的单子。第一份名单是2008-2018年,第二份是2010-2018年。在2008年至2018年在X轴上,第二个列表从2010年开始的情况下,我如何绘制它们?在
下面是简短代码的示例:
from matplotlib import pyplot as plt
Geb_b30 = [11, 10, 12, 14, 16, 19, 17, 14, 18, 17]
Geb_a30 = [12, 10, 13, 14, 12, 13, 18, 16]
fig, ax = plt.subplots()
ax.plot(Geb_b30, label='Prices 2008-2018', color='blue')
ax.plot(Geb_a30, label='Prices 2010-2018', color = 'red')
legend = ax.legend(loc='center right', fontsize='x-large')
plt.xlabel('years')
plt.ylabel('prices')
plt.title('Comparison of the different prices')
plt.show()
你应该创建一个新的清单,上面写着你的年龄。 然后,你可以指定你想在x轴上绘制的位置,例如用odoing years[10:18]来绘制
编辑:用正确的x轴更新
要告诉matplotlib希望点在x轴上的结束位置,必须显式提供x值。x轴值的大小必须与y值的大小相对应,但是独立数据集之间不需要有任何关系,正如您已经看到的那样。在
我建议您只需为每组点定义x值(即年份列表),并将它们传递到
ax.plot()
的参数中,如下所示:相关问题 更多 >
编程相关推荐