Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Hide "inner" {x,y}labels in label_outer too.#6619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
`ax.label_outer` used to hide only "inner" ticklabels; make it hide axeslabels too. (I couldn't find a way to just switch label visibility, soI just set the labels to the empty string instead.)
@anntzer I didn't find an example of """When plotting a grid of subplots that share axes, it might be interestingto display only some of the tick labels as well as some of the axes labels.The `label_outer` method provides a convenient way of dealing with thisby setting visible only the x tick and axis labels of the bottom row andthe y tick and axis labels of the left column."""importmatplotlib.pyplotaspltimportnumpyasnp# Dummy data to plott=np.linspace(0.0,5.0,501)s1=1.25*np.sin(2*np.pi*t)s2=np.exp(-t)s3=np.sin(4*np.pi*t)s4=np.sin(2*np.pi*t)*np.exp(-t)# Instantiate a 2x2 subplot grid with both shared x and y axes.fig,axs=plt.subplots(ncols=2,nrows=2,sharex=True,sharey=True)# Plot a data signal in each subplot and display:# - y tick and axis labels only for the first column;# - x tick and axis labels only for the last row.forax,s,titlein ((axs[0,0],s1,'Left labels ON'), (axs[0,1],s2,'All labels OFF'), (axs[1,0],s3,'Left & bottom labels ON'), (axs[1,1],s4,'Bottom labels ON')):ax.plot(t,s)ax.set_xlabel('This is x-axis')ax.set_ylabel('This is y-axis')ax.label_outer()# Display only the "relevant" tick & axis labels.ax.set_title(title)plt.show() if one wants to add a simple stand-alone example. And if one doesn't like such a small stand-alone example, then the examplesubplots_demo may be a good place to add the same kind of example. For the moment (without the current PR), the provided snippet results in |
I updated |
Nice! In fact, I hadn't directly proposed to modify the existing example in the case someone thought it would be useful to keep an example of the “cosmetricks” like plt.setp([a.get_xticklabels()forainaxarr[0, :]],visible=False)plt.setp([a.get_yticklabels()forainaxarr[:,1]],visible=False) which might give more fine-tuning possibilities if one doesn't simply want to label only the “outer” subplots. However if one had to choose, as |
If I wasn't clear in my previous comment: I agree with you about |
ax.label_outer
used to hide only "inner" ticklabels; make it hide axeslabels too. (I couldn't find a way to just switch label visibility, so
I just set the labels to the empty string instead.)