-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
transform_markers.py
34 lines (26 loc) · 1.25 KB
/
transform_markers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
''' A scatter plot using the `Palmer penguin dataset`_. This example
demonstrates color and marker mapping with basic plot elements. The chart
shows correlation between body mass and flipper length for three different
penguin species.
.. bokeh-example-metadata::
:sampledata: penguins
:apis: bokeh.plotting.figure.scatter, bokeh.transform.linear_cmap, bokeh.transform.factor_mark
:refs: :ref:`ug_basic_scatters_markers`, :ref:`ug_basic_data_transforming`
:keywords: alpha, colormap, markermap, scatter
.. _Palmer penguin dataset: https://github.com/allisonhorst/palmerpenguins
'''
from bokeh.plotting import figure, show
from bokeh.sampledata.penguins import data
from bokeh.transform import factor_cmap, factor_mark
SPECIES = sorted(data.species.unique())
MARKERS = ['hex', 'circle_x', 'triangle']
p = figure(title = "Penguin size", background_fill_color="#fafafa")
p.xaxis.axis_label = 'Flipper Length (mm)'
p.yaxis.axis_label = 'Body Mass (g)'
p.scatter("flipper_length_mm", "body_mass_g", source=data,
legend_group="species", fill_alpha=0.4, size=12,
marker=factor_mark('species', MARKERS, SPECIES),
color=factor_cmap('species', 'Category10_3', SPECIES))
p.legend.location = "top_left"
p.legend.title = "Species"
show(p)