Back to Seaborn

Objects.Plot.Scale

doc/_docstrings/objects.Plot.scale.ipynb

0.13.21.7 KB
Original Source
python
import seaborn.objects as so
from seaborn import load_dataset
diamonds = load_dataset("diamonds")
mpg = load_dataset("mpg").query("cylinders in [4, 6, 8]")
python
p1 = so.Plot(diamonds, x="carat", y="price")
p1.add(so.Dots()).scale(y="log")
python
p1.add(so.Dots(), color="clarity").scale(color="crest")
python
p1.add(so.Dots(), pointsize="carat").scale(pointsize=(2, 10))
python
p1.add(so.Dots(), color="carat").scale(color=(".4", "#68d"))
python
(
    p1.add(so.Dots(), color="carat")
    .scale(color=so.Continuous((".4", "#68d"), norm=(1, 3), trans="sqrt"))
)

The scale objects also offer an interface for configuring the location of the scale ticks (including in the legend) and the formatting of the tick labels:

python
(
    p1.add(so.Dots(), color="price")
    .scale(
        x=so.Continuous(trans="sqrt").tick(every=.5),
        y=so.Continuous().label(like="${x:g}"),
        color=so.Continuous("ch:.2").tick(upto=4).label(unit=""),
    )
    .label(y="")
)
python
(
    p1.add(so.Dots(color=".7"))
    .add(so.Line(), so.PolyFit(order=2))
    .scale(y="log")
    .limit(y=(250, 25000))
)
python
p2 = so.Plot(mpg, "cylinders").add(so.Bar(), so.Hist())
p2
python
p2.scale(x=so.Nominal())
python
p3 = (
    so.Plot(mpg, "weight", "acceleration", color="cylinders")
    .add(so.Dot(), marker="origin")
)
p3
python
p3.scale(color="deep")
python
p3.scale(
    color=["#49b", "#a6a", "#5b8"],
    marker={"japan": ".", "europe": "+", "usa": "*"},
)
python
p3.scale(
    color=so.Nominal(["#008fd5", "#fc4f30", "#e5ae38"]),
    marker=so.Nominal(order=["japan", "europe", "usa"])
)