-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
plotting: passing in ax is removing the wrong x labels #9737
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
While I still think that the highest plotting command should refuse to handle in def _handle_shared_axes(axarr, nplots, naxes, nrows, ncols, sharex, sharey):
if nplots > 1:
if sharex and nrows > 1:
- for ax in axarr[:naxes][:-ncols]: # only bottom row
+ for ax in axarr:
+ # only the last row of subplots should get x labels -> all other off
+ if not ax.is_last_row():
+ continue
[...]
if sharey and ncols > 1:
for i, ax in enumerate(axarr):
- if (i % ncols) != 0: # only first column
+ # only the first column should get y labels -> set all other to off
+ if not ax.is_first_col():
[...] See this example: %matplotlib inline
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.gridspec as gridspec
import pandas as pd
gs = mpl.gridspec.GridSpec(2, 2)
ax_tl = plt.subplot(gs[0,0])
ax_ll = plt.subplot(gs[1,0])
ax_tr = plt.subplot(gs[0,1])
ax_lr = plt.subplot(gs[1,1])
axes = [ax_tl, ax_ll, ax_tr, ax_lr]
df = pd.DataFrame({"a":[1,2,3,4,5,6], "b":[1,2,3,4,5,6]})
for ax in axes:
df.plot(x="a", y="b", title="title", ax=ax, sharex=False)
for ax in plt.gcf().get_axes():
if not ax.is_last_row():
for label in ax.get_xticklabels():
label.set_visible(False)
ax.xaxis.get_label().set_visible(False)
gs.tight_layout(plt.gcf()) |
I can do a PR with this two changes (adding the "sharex|y together with ax" check and using "is_last_row/first_col"), if someone says that this is the right way forward. |
Ok, just did that and uploaded in #9740 |
Thanks. I'll try to give it a look this weekend. |
Closed by #9740 |
Closing, as the PR is merged |
The following code will show the x labels on the right side, but actually it should show the labels at the bottom (or better: should show all!)
IMO: in
MPLPlot.__init__()
The text was updated successfully, but these errors were encountered: