我有一个数据框 df ,其中有 2 列,我想将它们绘制在一起并以天数作为索引:
| col1 | col2 | col3 | ...
2020-01-01 | 1 | 300000 | ...
2020-01-02 | 1000 | 600000 | ...
2020-01-03 | 3000 | 50000 | ...
通过
绘制 col1 + col2df[["col1", "col2"]].plot()
显示从 0 到 1.0 的值,并在顶部“1e6”,如本示例所示:https://i.sstatic.net/tJjgX.png
我想要 y 轴上的完整值范围,而不是科学记数法。我如何通过 pandas .plot() 或 matplotlib 来做到这一点?
您有多种选择:
选项一:使用Matplotlib
axes=fig.add_axes([0,0,1,1])
axes.set_xticks() # with list or range() inside
axes.set_yticks() # with list or range() inside
#You can also label the ticks with your desired values
axes.set_xticklabels() # with list or range() inside
axes.set_yticklabels() # with list or range() inside
选项二:更改 Pandas 设置
pd.set_option('display.float_format', lambda x: '%.3f' % x)
或
pd.options.display.float_format = '{:.2f}'.format
我相信选项一更好,因为您只需要它来绘制图表,而不必修改数据框列。
干杯!
您可以尝试更改
axes.formatter.limits
的 rcParams
属性:
plt.rcParams["axes.formatter.limits"] = (-5, 12)
如果轴范围的 log10 小于第一个或大于第二个,Matplotlib 使用科学计数法。
您可以自定义所需输出的下限和上限。
非常简单。只需使用“ylim”并给出原始数据的范围。 这为我解决了这个问题!
dataframe.plot.scatter(x='NoOfStaff', y='费用', c='CovidYesNo', cmap='rainbow', ylim=(0,100000))
使用
.set_ylim([min,max])
设置绘图的 y 轴限制