Skip to content
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

Recent hotfix made sns.relplot incompatible with latex plotting. #2673

Closed
NotSpecial opened this issue Oct 2, 2021 · 5 comments
Closed

Recent hotfix made sns.relplot incompatible with latex plotting. #2673

NotSpecial opened this issue Oct 2, 2021 · 5 comments
Labels
Milestone

Comments

@NotSpecial
Copy link

NotSpecial commented Oct 2, 2021

Hi, and first of all thanks for the great library!

I have discovered a problem with a recent hotfix (this line) and latex plotting.

Concretely, the hotfix prepends underscores to all plot variables, e.g. turning x into_x and only changes the labels later.
This causes a problem with the FacetGrid underlying relplot, which calls tight_layout here.

For some reason, this causes matplotlib to render the plot with the axis labels including underscores. I believe it happens to find margins, but I am not sure. In any case, the latex render cannot handle the underscores and crashes.

Affected versions

0.11.2 only; version 0.11.1 (without the hotfix) works fine.

Steps to reproduce

import seaborn as sns
import matplotlib as mpl
import pandas as pd
mpl.rcParams.update({
        'text.usetex': True,
})

testdata = pd.DataFrame({'x': [1, 2], 'y': [2, 3]})
sns.relplot(data=testdata, x='x', y='y');

This raises:

RuntimeError: latex was not able to process the following string:
b'_x'

Possible fixes

Prepend with something more latex friendly instead of underscores, e.g. temp or anything.

@mwaskom
Copy link
Owner

mwaskom commented Oct 2, 2021

Ah, vexing. I think \_{var} should work, right?

Unfortunately, displot has a similar problem if you pass a name-less object as a faceting variable.

@mwaskom mwaskom added this to the v0.12.0 milestone Oct 2, 2021
@mwaskom mwaskom added the bug label Oct 2, 2021
@NotSpecial
Copy link
Author

Yes, \_{var} would work as well 👍

@mwaskom
Copy link
Owner

mwaskom commented Apr 3, 2022

@NotSpecial are you still having this issue? I cannot reproduce it on master, using matplotlib 3.5.1. Perhaps matplotlib added something in their latex code to escape leading underscores? This also works fine:

f, ax = plt.subplots()
ax.set_ylabel("_y")

image

@mwaskom
Copy link
Owner

mwaskom commented Apr 3, 2022

I believe this was handled upstream: matplotlib/matplotlib#20706

@NotSpecial
Copy link
Author

NotSpecial commented Apr 4, 2022

Great news! I can confirm that it works for me again as well with matplotlib version 3.5.1 and seaborn version 0.11.2. Thanks for checking up on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants