mwaskom / seaborn

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

The errorbar cannot be aligned with the bar, if the width of the bar is modified in next-generation interface #2987

Open liuzj039 opened 2 years ago

liuzj039 commented 2 years ago

After changing the width, the errorbar still seems to appear in the original position. Is it necessary to add width parameters to other marks like Range as well?

import seaborn as sns
import seaborn.objects as so
from seaborn import load_dataset
tips = load_dataset("tips")
(
    so.Plot(tips, x='day', y='total_bill', color='sex')
    .add(so.Bar(width=0.3), so.Agg(), so.Dodge(by=['color']))
    .add(so.Range(), so.Est(), so.Dodge(by=['color']))
    .theme(sns.axes_style('ticks'))
)

image

I noticed that there is a gap parameter in Dodge, but it doesn't seem to work for this case.

(
    so.Plot(tips, x='day', y='total_bill', color='sex')
    .add(so.Bar(width=0.3), so.Agg(), so.Dodge(gap=0.5, by=['color']))
    .add(so.Range(), so.Est(), so.Dodge( by=['color']))
    .theme(sns.axes_style('ticks'))
)

image

Please forgive me if I missed something.

mwaskom commented 2 years ago

Hi, I don't think you've missed anything. width is a bit of a rough edge — it's potentially important for all marks (because it could be needed to dodge properly) but not a relevant property for all marks. ggplot has width of the parameter of position_dodge which I always thought was a little confusing.

Hopefully this will improve as part of addressing #2911, and maybe #2982.

liuzj039 commented 2 years ago

Very much looking forward to the following updates

thobanster commented 10 months ago

Following up on this, until this issue gets fixed, how would a user write additional code so as to align the error bar locations with the bars on the barplot?