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

seaborn.objects incorrectly plots secondary y-axis #3614

Open
SamKG opened this issue Jan 10, 2024 · 1 comment · May be fixed by #3696
Open

seaborn.objects incorrectly plots secondary y-axis #3614

SamKG opened this issue Jan 10, 2024 · 1 comment · May be fixed by #3696

Comments

@SamKG
Copy link

SamKG commented Jan 10, 2024

Hello,
Thanks for the great work on seaborn.objects, I really like it.

I noticed an issue however when trying to plot on a secondary y-axis using Plot.on(). Essentially, the second axis seems to be double-plotted - once using the original axis, and again using the correct second axis. This leads to overlapping ticks and the grid lines being drawn above the first plot's line.

Minimal reproduction:

from matplotlib import pyplot as plt
import seaborn as sns
import seaborn.objects as so
import pandas as pd

# create simple dataframe

df = pd.DataFrame(
    {
        "X": [1, 2, 3, 4],
        "Y1": [1, 2, 3, 4],
        "Y2": [0, 3, 9, 81],
    }
)

sns.set_theme()

f = plt.figure(figsize=(8, 4))
# get the axis
ax = f.add_subplot(111)
ax2 = ax.twinx()

(
    so.Plot(df, x="X", y="Y1")
    .add(so.Line(color="C0"))
    .on(ax)
    .plot()
)

(
    so.Plot(df, x="X", y="Y2")
    .add(so.Line(color="C1"))
    .on(ax2)
    .plot()
)

plt.show()

image

I managed a temporary workaround using the following:

ax2.grid(False)
ax2.yaxis.tick_right()

but it's still weird that it happens to begin with. I'd be happy to take a stab at fixing it if anyone could point me in the right direction

@mwaskom
Copy link
Owner

mwaskom commented Jan 16, 2024

Yeah that's a weird one! I don't have any immediate hypotheses, unfortunately.

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

Successfully merging a pull request may close this issue.

2 participants