简体   繁体   English

删除 matplotlib 子图中的轴?

[英]Remove axes in matplotlib subplots?

I've got a pandas dataframe with 4 columns and a date range as the index.我有一个带有 4 列和一个日期范围作为索引的 pandas 数据框。 After showing the trend lines on four subplots using this code, I realized I don't want the y axis ticks or labels, but I can't find any advice on removing them from the subplots;在使用此代码在四个子图上显示趋势线后,我意识到我不想要 y 轴刻度或标签,但我找不到任何关于从子图中删除它们的建议; everything I try only works on the bottom plot.我尝试的一切都只适用于底部情节。

plot4 = CZBCdf2.plot(subplots=True,figsize=(10,4),sharex=True)

The typical way of removing axis in matplotlib is:在 matplotlib 中删除轴的典型方法是:

import matplotlib.pyplot as plt

plt.axis('off')

This, however, is a general instruction in matplotlib.然而,这是 matplotlib 中的一般指令。 To set the axis to invisible you can do (using a subplot):要将轴设置为不可见,您可以执行以下操作(使用子图):

ax.xaxis.set_visible(False) # same for y axis.

You seem to be calling the plot from other source.您似乎是从其他来源调用该图。 If this instructions don't do the stuff you need provide more of your code to see what might be the procedure to achieve that.如果此说明没有完成您需要提供更多代码以查看实现该目标的过程。

Set yticks=[]设置yticks=[]

So, in your example:所以,在你的例子中:

plot4 = CZBCdf2.plot(subplots=True,figsize=(10,4),sharex=True, yticks=[])

删除情节周围任何东西的完整解决方案

figure, axis = plt.subplots(1, figsize=[10,3])
axis.plot(...)
axis.xaxis.set_visible(False)
axis.yaxis.set_visible(False)
for spine in ['top', 'right', 'left', 'bottom']:
   axis.spines[spine].set_visible(False)
figure.savefig('demo.png', bbox_inches='tight', transparent="True", pad_inches=0,  )

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

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