Hist#
Download this notebook from GitHub (right-click to download).
import hvplot.pandas # noqa
# hvplot.extension("matplotlib")
hist
is often a good way to start looking at continuous data to get a sense of the distribution. Similar methods include kde
(also available as density
).
from bokeh.sampledata.autompg import autompg_clean
autompg_clean.sample(n=5)
mpg | cyl | displ | hp | weight | accel | yr | origin | name | mfr | |
---|---|---|---|---|---|---|---|---|---|---|
86 | 13.0 | 8 | 350.0 | 145 | 3988 | 13.0 | 73 | North America | chevrolet malibu | chevrolet |
249 | 20.2 | 8 | 302.0 | 139 | 3570 | 12.8 | 78 | North America | mercury monarch ghia | mercury |
64 | 14.0 | 8 | 351.0 | 153 | 4129 | 13.0 | 72 | North America | ford galaxie 500 | ford |
82 | 28.0 | 4 | 98.0 | 80 | 2164 | 15.0 | 72 | North America | dodge colt (sw) | dodge |
245 | 39.4 | 4 | 85.0 | 70 | 2070 | 18.6 | 78 | Asia | datsun b210 gx | datsun |
autompg_clean.hvplot.hist("weight")
When using by
the plots are overlaid by default. To create subplots instead, use subplots=True
.
autompg_clean.hvplot.hist("weight", by="origin", subplots=True, width=250)
You can also plot histograms of datetime data
import pandas as pd
from bokeh.sampledata.commits import data as commits
commits = commits.reset_index().sort_values("datetime")
commits.head(3)
datetime | day | time | |
---|---|---|---|
4915 | 2012-12-29 11:57:50-06:00 | Sat | 11:57:50 |
4914 | 2013-01-02 17:46:43-06:00 | Wed | 17:46:43 |
4913 | 2013-01-03 16:28:49-06:00 | Thu | 16:28:49 |
commits.hvplot.hist(
"datetime",
bin_range=(pd.Timestamp('2012-11-30'), pd.Timestamp('2017-05-01')),
bins=54,
)
If you want to plot the distribution of a categorical column you can calculate the distribution using Pandas’ method value_counts
and plot it using .hvplot.bar
.
autompg_clean["mfr"].value_counts().hvplot.bar(invert=True, flip_yaxis=True, height=500)
This web page was generated from a Jupyter notebook and not all interactivity will work on this website. Right click to download and run locally for full Python-backed interactivity.
Download this notebook from GitHub (right-click to download).