Python 从折线图中删除小数点
我的年份数据在表格上显示时是一个整数,但当我将其输入x轴下的折线图时,它会在一年中的不同时间分裂。有谁能帮我把它分为一年吗 以下是我当前的代码:Python 从折线图中删除小数点,python,python-2.7,matplotlib,Python,Python 2.7,Matplotlib,我的年份数据在表格上显示时是一个整数,但当我将其输入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 P
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()
我认为您需要指定列
Year
为datetime
对象:
df['Year'] = pd.to_datetime(df['Year'], format='%Y')
输出:
创建axis实例ax,绘制df,然后使用
ax.xaxis.set\u major\u格式化程序(FormatStrFormatter(“%d”)