Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从折线图中删除小数点_Python_Python 2.7_Matplotlib - Fatal编程技术网

Python 从折线图中删除小数点

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

我的年份数据在表格上显示时是一个整数,但当我将其输入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()

我认为您需要指定列
Year
datetime
对象:

df['Year'] = pd.to_datetime(df['Year'], format='%Y')
输出:

创建axis实例ax,绘制df,然后使用
ax.xaxis.set\u major\u格式化程序(FormatStrFormatter(“%d”)