python - 从折线图中删除小数

标签 python 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 Profit")
 plt.show()

enter image description here

最佳答案

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

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

输出: enter image description here

关于python - 从折线图中删除小数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52646772/

相关文章:

python - 当我运行Python程序时,pygame窗口打开片刻,然后退出

python - 您将以何种方式提出一种算法来检测不同对象之间的碰撞?

python条形图条形上的总标签

python - 在 matplotlib bar_label 中隐藏小于 n 的条形标签

python - 如何用不等式分割一个 numpy 数组?

python - 我可以异步执行 "apply"中的函数到 pandas 数据帧吗?

python - 获取 DataFrame 列作为值列表

python - Python 中的 MATLAB ind2sub 等价物

python - python matplotlib 中带有日期时间的 barplot 的奇怪行为

python - 从 3D Numpy 数组绘制红色 channel