Jittered Strip Plot#
A scatter plot with horizontal jitter to show individual penguins’ body mass grouped by species. Points are colored by species and positioned along the x-axis using slight jitter, with category labels added for clarity.
import numpy as np
import hvplot.pandas # noqa
np.random.seed(1)
df = hvplot.sampledata.penguins('pandas')
df = df[df['species'].notna()].copy()
species_map = {'Adelie': 0, 'Chinstrap': 1, 'Gentoo': 2}
df['x'] = df['species'].map(species_map) + np.random.uniform(-0.2, 0.2, size=len(df))
df.hvplot.scatter(
x='x',
y='body_mass_g',
title='Simulated Jittered Strip Plot (Bokeh)',
xticks=[(0, 'Adelie'), (1, 'Chinstrap'), (2, 'Gentoo')],
by='species',
xlabel='Species',
ylabel='Body Mass (g)',
tools=['hover'],
)
import hvplot.pandas # noqa
import numpy as np
hvplot.extension('matplotlib')
np.random.seed(1)
df = hvplot.sampledata.penguins('pandas')
df = df[df['species'].notna()].copy()
species_map = {'Adelie': 0, 'Chinstrap': 1, 'Gentoo': 2}
color_map = {'Adelie': 'blue', 'Chinstrap': 'green', 'Gentoo': 'orange'}
df['x'] = df['species'].map(species_map) + np.random.uniform(-0.2, 0.2, size=len(df))
df['color'] = df['species'].map(color_map)
df.hvplot.scatter(
x='x',
y='body_mass_g',
by='color',
title='Jittered Strip Plot by Species (Matplotlib)',
xlabel='Species',
ylabel='Body Mass (g)',
xticks=[(0, 'Adelie'), (1, 'Chinstrap'), (2, 'Gentoo')],
)
See also
This web page was generated from a Jupyter notebook and not all
interactivity will work on this website.