import pandas as pd
import altair as alt
import seaborn as sns
from matplotlib import pyplot as plt
Data from Palmer Penguins R package
= pd.read_csv("https://pos.it/palmer-penguins-github-csv") penguins
"species").size().reset_index(name = "count") penguins.groupby(
species | count | |
---|---|---|
0 | Adelie | 152 |
1 | Chinstrap | 68 |
2 | Gentoo | 124 |
= ["#FF8C00", "#A020F0", "#008B8B"]
colors = 3) sns.set_palette(colors, n_colors
"bill_ratio"] = (
penguins["bill_length_mm"] / penguins["bill_depth_mm"]
penguins[
)
sns.displot(penguins, = "bill_ratio",
x = "species",
hue = "kde", fill = True, aspect = 2, height = 3)
kind plt.show()
sns.displot(penguins, = "bill_depth_mm",
x = "species",
hue = "kde", fill = True,
kind = 2, height = 3)
aspect
plt.show()
sns.displot(penguins, = "bill_length_mm",
x = "species",
hue = "kde", fill = True,
kind = 2, height = 3)
aspect plt.show()
= alt.Scale(domain = ['Adelie', 'Chinstrap', 'Gentoo'],
scale range = colors)
=60).encode(
alt.Chart(penguins).mark_circle(size'bill_length_mm',
alt.X(=alt.Scale(zero=False)
scale
),'bill_depth_mm',
alt.Y(=alt.Scale(zero=False)
scale
),= alt.Color('species', scale = scale),
color =['species', 'sex', 'island']
tooltip )