File: density_facet.py

package info (click to toggle)
python-altair 5.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,952 kB
  • sloc: python: 25,649; sh: 14; makefile: 5
file content (28 lines) | stat: -rw-r--r-- 637 bytes parent folder | download
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
"""
Faceted Density Estimates
-------------------------
Density estimates of measurements for each iris flower feature
"""
# category: distributions

import altair as alt
from vega_datasets import data

source = data.iris()

alt.Chart(source).transform_fold(
    ['petalWidth', 
     'petalLength', 
     'sepalWidth', 
     'sepalLength'], 
    as_ = ['Measurement_type', 'value']
).transform_density(
    density='value', 
    bandwidth=0.3, 
    groupby=['Measurement_type'], 
    extent= [0, 8]
).mark_area().encode(
    alt.X('value:Q'), 
    alt.Y('density:Q'),
    alt.Row('Measurement_type:N')
).properties(width=300, height=50)