seaborn.objects.Bar#

class seaborn.objects.Bar(artist_kws=<factory>, color=<'C0'>, alpha=<0.7>, fill=<True>, edgecolor=<depend:color>, edgealpha=<1>, edgewidth=<rc:patch.linewidth>, edgestyle=<'-'>, width=<0.8>, baseline=<0>)#

A bar mark drawn between baseline and data values.

This mark defines the following properties:

color, alpha, fill, edgecolor, edgealpha, edgewidth, edgestyle, |width|, |baseline|

See also

Bars

A faster bar mark with defaults more suitable for histograms.

Examples

The mark draws discrete bars from a baseline to provided values:

so.Plot(flights["month"], flights["passengers"]).add(so.Bar())
../_images/objects.Bar_1_0.png

The bars are oriented depending on the x/y variable types and the orient parameter:

so.Plot(flights["passengers"], flights["month"]).add(so.Bar())
../_images/objects.Bar_3_0.png

A common usecase will be drawing histograms on a variable with a nominal scale:

so.Plot(penguins, x="species").add(so.Bar(), so.Hist())
../_images/objects.Bar_5_0.png

When mapping additional variables, the bars will overlap by default:

so.Plot(penguins, x="species", color="sex").add(so.Bar(), so.Hist())
../_images/objects.Bar_7_0.png

Apply a move transform, such as a Dodge or Stack to resolve them:

so.Plot(penguins, x="species", color="sex").add(so.Bar(), so.Hist(), so.Dodge())
../_images/objects.Bar_9_0.png

A number of properties can be mapped or set:

(
    so.Plot(
        penguins, x="species",
        color="sex", alpha="sex", edgestyle="sex",
    )
    .add(so.Bar(edgewidth=2), so.Hist(), so.Dodge("fill"))
)
../_images/objects.Bar_11_0.png

Combine with Range to plot an estimate with errorbars:

(
    so.Plot(penguins, "body_mass_g", "species", color="sex")
    .add(so.Bar(alpha=.5), so.Agg(), so.Dodge())
    .add(so.Range(), so.Est(errorbar="sd"), so.Dodge())
)
../_images/objects.Bar_13_0.png