-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Interaction between xtick label size and height changes FacetGrid ticks #2293
Comments
Actually, going back through my example, it appears the above is not sufficient to reproduce it. You'd also need to run the following: Which makes me think this issue might be too niche to be of real concern. But it is weird -- how does seaborn determine whether to show the xticks / xticklabels on the upper facets? |
I think that if this is a bug (and it seems to be?) it's probably a bug at the matplotlib layer. As far as I recall (the With that said, I'm having trouble reproducing using straight matplotlib, e.g. plt.style.use({'figure.subplot.right': .96, 'figure.subplot.left': .075})
with sns.axes_style('white'), sns.plotting_context('notebook', rc={'xtick.labelsize': 12}):
f, axs = plt.subplots(2, 3, sharex=True, sharey=True, figsize=(3 * 2.6, 2 * 2.6))
f.tight_layout()
for i, ax in enumerate(axs.flat):
data = tmp[tmp["i"] == i]
ax.plot(data["x"], data["y"])
ax.set_title(f"i = {i}")
plt.setp(axs[:, 0], ylabel="y")
plt.setp(axs[-1, :], xlabel="x")
f.tight_layout()
sns.despine() but the problem seems very narrow so it make take some futzing to get the order of operations exact... |
FWIW mapping a plotting function doesn't seem required: plt.style.use({'figure.subplot.right': .96, 'figure.subplot.left': .075})
with sns.axes_style('white'), sns.plotting_context('notebook', rc={'xtick.labelsize': 12}):
g = sns.FacetGrid(tmp, col='i', col_wrap=3, height=2.6) reproduces it (slightly differently) |
Actually ... just noticed that your example uses |
It does seem to be something with N = 6
x = np.linspace(0, 10)
x = np.vstack(N*[x])
A = np.random.rand(N) * np.eye(N)
b = np.random.rand(N, 1)
y = A@x+b
i = np.array([i*np.ones_like(x[i]) for i in range(N)]).flatten()
data = {'x': x.flatten(), 'y': y.flatten(), 'i': i, 'j': i//2, 'k': np.round((i/2)+.1)-i//2}
tmp = pd.DataFrame(data)
plt.style.use({'figure.subplot.right': .96, 'figure.subplot.left': .075})
with sns.axes_style('white'), sns.plotting_context('notebook', rc={'xtick.labelsize': 12}):
g = sns.FacetGrid(tmp, col='j', row='k', height=2.6) It looks like the main difference is that when That said, I am unable reproduce the problem in a similar way to how col_wrap operates using pure matplotlib plt.style.use({'figure.subplot.right': .96, 'figure.subplot.left': .075})
with sns.axes_style('white'), sns.plotting_context('notebook', rc={'xtick.labelsize': 12}):
f = plt.figure(figsize=(3*2.6, 2*2.6))
axs = np.empty(6, object)
axs[0] = f.add_subplot(2, 3, 1)
for i in range(1, 6):
axs[i] = f.add_subplot(2, 3, i+1, sharex=axs[0], sharey=axs[0])
axs = axs.reshape((2, 3))
f.tight_layout()
for i, ax in enumerate(axs.flat):
data = tmp[tmp["i"] == i]
ax.plot(data["x"], data["y"])
ax.set_title(f"i = {i}")
plt.setp(axs[:, 0], ylabel="y")
plt.setp(axs[-1, :], xlabel="x")
f.tight_layout()
for ax in axs[0, :]:
for label in ax.get_xticklabels():
label.set_visible(False)
ax.xaxis.offsetText.set_visible(False)
for ax in axs[:, 1]:
for label in ax.get_yticklabels():
label.set_visible(False)
ax.yaxis.offsetText.set_visible(False)
for ax in axs[:, 2]:
for label in ax.get_yticklabels():
label.set_visible(False)
ax.yaxis.offsetText.set_visible(False)
sns.despine() Finally: I dropped some print statements in that |
I'm finding that I can't reproduce this on current versions of things, so I am going to close as a weird upstream problem. Ping if you run into it again. |
Hi @mwaskom, I recently updated seaborn from v.010 and found this problem again, but strangely only when using Here the example bothering me:
The last xtick label, here "2021" is still visible on the upper graphs. But for other context it disappears. Here with This probably comes from some strange issue with the size formating, but I don't know matplotlib enought to work it out. Versions used:
|
Thanks @donok1 that's reproducible in my dev environment too. I really have no clue what might be causing this, but here is an experiment that may shed some insight:
Play around with |
Thanks @mwaskom for the great tip. |
I've found what seems to be a weird bug where some interaction between the
height
argument of FacetGrid and the rcParamxtick.labelsize
can result in xtick labels being visible on the upper facets of a multi-row FacetGrid, like so:The upper facets should not have any xlabels on them, yet they do.
Code to reproduce this example:
Changing either height or the
xtick.labelsize
can change the behavior:Weirdly that last one looks different when I save it as a png or svg vs view it in a notebook (where 4 and 6 are visible on the upper facets, but not 10).
This is all on Ubuntu 18.04, with seaborn version 0.11.0 and matplotlib version 3.0.3 (svg backend)
The text was updated successfully, but these errors were encountered: