【发布时间】:2019-03-09 20:22:25
【问题描述】:
我的年份数据在表格上显示时是一个整数,但是当我将其输入到 x 轴下方的折线图中时,它会在一年中的不同时间自行拆分。谁能帮我把它分类到年份本身?
这是我当前的代码:
df.plot( x = "Year", kind="line", figsize = (10,5), legend = True)
plt.ticklabel_format(style="plain", axis="y")
plt.xlabel("Year")
plt.ylabel("Profit")
plt.title("Yearly Profit")
plt.show()
【问题讨论】:
-
创建一个轴实例 ax,绘制你的 df,然后使用
ax.xaxis.set_major_formatter(FormatStrFormatter('%d'))
标签: python python-2.7 matplotlib