Skip to content

Commit

Permalink
Merge pull request #1520 from iliatimofeev/it-violin-plot
Browse files Browse the repository at this point in the history
Violin plot (a kind of)
  • Loading branch information
jakevdp committed May 24, 2019
2 parents b7933cc + d7b0e7f commit c7cb3f6
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions altair/examples/violine_plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""
Violinplot
----------
This example shows how to make a king of a Violinplot.
"""
# category: other charts
import altair as alt
from altair import datum
from vega_datasets import data

source = data.cars.url

violinplot = alt.Chart(source).transform_filter(
datum.Miles_per_Gallon > 0
).transform_bin(
['bin_max', 'bin_min'], field='Miles_per_Gallon', bin=alt.Bin(maxbins=20)
).transform_calculate(
binned=(datum.bin_max + datum.bin_min) / 2
).transform_aggregate(
value_count='count()', groupby=['Origin', 'binned']
).transform_impute(
impute='value_count', groupby=['Origin'], key='binned', value=0
).mark_area(
interpolate='monotone',
orient='horizontal'
).encode(
x=alt.X(
'value_count:Q',
title=None,
stack='center',
axis=alt.Axis(labels=False, values=[0],grid=False, ticks=True),
),
y=alt.Y('binned:Q', bin='binned', title='Miles per Gallon'),
color=alt.Color('Origin:N', legend=None),
column=alt.Column(
'Origin:N',
header=alt.Header(
titleOrient='bottom',
labelOrient='bottom',
labelPadding=0,
),
),
).properties(
width=80
).configure_facet(
spacing=0
).configure_view(
stroke=None
)

violinplot

0 comments on commit c7cb3f6

Please sign in to comment.