Skip to content

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

@divingtobi

Description

@divingtobi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions