简体   繁体   English

指定 Pandas plot() y 轴的步长

[英]Specifying steps in y-axis of Pandas plot()

I use the following plot function to create a line chart of a Pandas dataframe我使用以下绘图函数创建 Pandas 数据框的折线图

row = df.iloc[0].astype(int)
plt.subplot(1, 2, 1)
row.plot(marker='o', fontsize=20, ylabel=yax_label)
plt.show()

Problem is that, the y steps are shown in float (0.5 steps).问题是,y 步以浮点数显示(0.5 步)。 Is there any way to control that?有什么办法可以控制吗? For example, 3,4,5,6,7 as integers.例如,3、4、5、6、7 作为整数。

在此处输入图片说明

You can use .set_yticks() :您可以使用.set_yticks()

(I can't run your code, send an example) (我无法运行您的代码,请发送示例)

import matplotlib.pyplot as plt

fig, axe = plt.subplots(1, 3, constrained_layout=True)

axe[0].plot(range(10))
axe[0].set_yticks(np.arange(0,10,0.5))

axe[1].plot(range(10))
axe[1].set_yticks(np.arange(0,10))

axe[2].plot(range(10))
axe[2].set_yticks(np.arange(0,10,2))
plt.show()

Output:输出:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM