doc/_docstrings/objects.Plot.scale.ipynb
import seaborn.objects as so
from seaborn import load_dataset
diamonds = load_dataset("diamonds")
mpg = load_dataset("mpg").query("cylinders in [4, 6, 8]")
p1 = so.Plot(diamonds, x="carat", y="price")
p1.add(so.Dots()).scale(y="log")
p1.add(so.Dots(), color="clarity").scale(color="crest")
p1.add(so.Dots(), pointsize="carat").scale(pointsize=(2, 10))
p1.add(so.Dots(), color="carat").scale(color=(".4", "#68d"))
(
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:
(
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="")
)
(
p1.add(so.Dots(color=".7"))
.add(so.Line(), so.PolyFit(order=2))
.scale(y="log")
.limit(y=(250, 25000))
)
p2 = so.Plot(mpg, "cylinders").add(so.Bar(), so.Hist())
p2
p2.scale(x=so.Nominal())
p3 = (
so.Plot(mpg, "weight", "acceleration", color="cylinders")
.add(so.Dot(), marker="origin")
)
p3
p3.scale(color="deep")
p3.scale(
color=["#49b", "#a6a", "#5b8"],
marker={"japan": ".", "europe": "+", "usa": "*"},
)
p3.scale(
color=so.Nominal(["#008fd5", "#fc4f30", "#e5ae38"]),
marker=so.Nominal(order=["japan", "europe", "usa"])
)