简体   繁体   English

matplotlib子图轴标签

[英]matplotlib subplot axis label

I have a subplot, its x-axis label uses voltages, its csv data column values increase from 0 to 30 and then decrease from 30 to 0. when I use this code it gives me this plot 我有一个子图,其x轴标签使用电压,其csv数据列值从0增大到30,然后从30减小到0。当我使用此代码时,它给出了这个图

ax2.plot(df_raw.index, df_raw.loc[:,"data_column"])

Matplolib子图

When I use below code I got the plot as as shown below 当我使用下面的代码时,我得到了如下图所示的图

ax2.plot(df_raw.loc[:,"voltage"], df_raw.loc[:,"data_column"])

在此处输入图片说明

What I really want is as shown below 我真正想要的是如下所示

在此处输入图片说明

Try to set the label manually: 尝试手动设置标签:

df = pd.DataFrame({'vol': list(range(101)) + list(range(99,0,-1)),
                   'val': [0]*10 + [1]*180 +[0]*10})

fig, ax = plt.subplots()
ax.plot(df.index, df.val)

ax.set_xticklabels(df.vol[ax.get_xticks()]
                 .fillna(0).astype(int))
plt.show()

在此处输入图片说明

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

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