I hacked
matplotlib
‘s scatter plot to give the people what they want: a dot chart (aka strip
plot). You can install it withpip install dotplotlib
, or see the source
code here.
1 | Current stars: 9 |
Great things come in tiny packages. A bare minimum extension library for creating tree dot plots, strip plots or dot
charts w/ matplotlib or seaborn in Python
- Designed to work with
matplotlib
andseaborn
in Python - Fully customizable
installation
1 | pip install dotplotlib |
usage
dotplotlib
can be used to generate dot charts with minimal code. Here are some examples:
Example 1: Simple Dot Chart
.dotchart
returns x
and y
lists that can be inputted straight into matplotlib
or seaborn
scatterplots.
1 | from dotplotlib import dotchart |
Example 2: Dot Chart with Color Mapping
Pass the data you would like to color by to the color_by=
argument.
Returns an extra list c
that should be passed into the c=
parameter if using matplotlib
or hue=
if
using seaborn
.
1 | from dotplotlib import dotchart |
Example 3: Using make_dotchart
to plot in one step
Instead of just giving you x, y
lists to make the plot yourself, make_dotplot()
actually generates the plot.
1 | from dotplotlib import make_dotchart |
Example 4: Plotting in a Jupyter Notebook
If plotting inline, use the default .dotchart()
to obtain x
and y
lists, and then adjust as necessary with one of
the following:
1 | plt.figure(figsize=(12,6)) # or |
preset themes
custom:lavender
cmap
Any cmap value supported by matplotlib (see here)
will work when passed into theme='viridis'
.
viridis:
gnuplot:
gallery:
features
- generate strip plots/dot charts by exploiting
matplotlib/seaborn
scatterplots - supports any cmap color profile
- the data can be automatically sorted for better visualization, especially when using color mapping.
- accepts both list and pandas.Series as input data.
- set custom labels, titles, and dot sizes for your charts.
- works with Jupyter Notebook
attribution
- pjarzabek
- m3
- ddlegal