mwaskom / seaborn

Statistical data visualization in Python
https://seaborn.pydata.org
BSD 3-Clause "New" or "Revised" License
12.59k stars 1.93k forks source link

Dual axis plot broken in 0.13.2 (vs. 0.12.2) #3745

Open divingtobi opened 3 months ago

divingtobi commented 3 months ago

The following code produces a dual axis plot with properly labelled tick marks on both axis with seaborn 0.12.2 (python 3.10.11). However, with seaborn 0.13.2 (python 3.11.4) the tick labels of the right axis are duplicated on the left axis.

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

df = pd.DataFrame(
    {"x": [1, 2, 3, 4, 5], "y1": [5, 2, 1, 6, 2], "y2": [1000, 240, 1300, 570, 120]}
)
fig, ax1 = plt.subplots(1, 1, figsize=(6, 4))
ax2 = ax1.twinx()
ax1.tick_params(axis="x", labelrotation=45)
p1 = (
    so.Plot(df, x="x", y="y1")
    .add(so.Bar(width=0.7))
    .label(x="Month", y="Data 1", title="TITLE")
    .on(ax1)
    .plot()
)
p2 = (
    so.Plot(df, x="x", y="y2")
    .add(so.Line(color="orange", linewidth=3))
    .label(y="Data 2", title="TITLE")
    .scale(y=so.Continuous().label(like="{x:,.0f}"))
    .on(ax2)
    .plot()
)

Result with 0.13.2: image

Result with 0.12.2: image

mwaskom commented 3 months ago

Are you holding the matplotlib version constant here?

MaozGelbart commented 3 months ago

Looks like a duplicate of #3614. Can confirm the issue here is fixed by #3696.