import pandas as pd
import altair as alt
import seaborn as sns
from matplotlib import pyplot as plt
Palmer Penguins (.ipynb)
In [1]:
Data from Palmer Penguins R package
In [2]:
= pd.read_csv("https://pos.it/palmer-penguins-github-csv") penguins
In [3]:
"species").size().reset_index(name = "count") penguins.groupby(
species | count | |
---|---|---|
0 | Adelie | 152 |
1 | Chinstrap | 68 |
2 | Gentoo | 124 |
In [4]:
= ["#FF8C00", "#A020F0", "#008B8B"]
colors = 3) sns.set_palette(colors, n_colors
In [5]:
"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()
In [7]:
= alt.Scale(domain = ['Adelie', 'Chinstrap', 'Gentoo'],
scale range = colors)
In [8]:
=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 )