简体   繁体   中英

Remove axes in matplotlib subplots?

I've got a pandas dataframe with 4 columns and a date range as the index. 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; 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:

import matplotlib.pyplot as plt

plt.axis('off')

This, however, is a general instruction in 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=[]

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,  )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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