This is a Python module that contains some useful plotting utilities. Current functionalities include:
- 3D histograms: visualizing multiple distributions easily and elegantly [doc], [example]
- Discrete histogram, suitable for visualizing categorical values [doc], [example]
- Choropleth map (aka "heat map") of the United States, on both state and county level [doc], [example]
- Correlation matrix (aka "covariance matrix") of a dataset [doc], [example]
- and the one-to-one scatter plots for the variables within the dataset [doc]
- "Bin-and-mean" plot, a good way to uncover the dependency between two variables [doc], [example]
- A get_colors() function that conveniently queries different qualitative color palettes [doc], [example]
- Pie chart to visualize proportions, more convenient than matplotlib's
pie()
function [doc], [example] - Time series plotting, for visualizing single or multiple time series data quickly and elegantly [doc], [example]
- Plotting with upper/lower error bounds, which displays error bounds as shaded areas [doc], [example]
Plots 3D histograms. Useful for comparing multiple distributions.
>>> import plot_utils as pu
>>> pu.histogram3d(X) # X is the dataset to be visualized
Plots state-level choropleth maps from a Python dictionary or Pandas Series/DataFrame.
>>> import plot_utils as pu
>>> pu.choropleth_map_state(state_level_data)
Plots county-level choropleth map from a Python dictionary or Pandas Series/DataFrame.
>>> import plot_utils as pu
>>> pu.choropleth_map_county(county_level_data)
Plots correlation matrix of a dataset, X
. Also automatically generates scatter plots of variables with high correlations.
>>> import plot_utils as pu
>>> pu.plot_correlation(X, scatter_plots=True)
Useful for discovering correlation within data.
>>> import plot_utils as pu
>>> pu.bin_and_mean(x, y, logx=True,
xlabel='Maximum strain [%]',ylabel='Goodness-of-fit scores')
Easy querying of distinguishable color palettes.
>>> import seaborn as sns
>>> import plot_utils as pu
>>> colors = pu.get_colors(color_scheme='tab10',N=10)
>>> sns.palplot(colors)
Easy querying of distinguishable line specs.
>>> import plot_utils as pu
>>> line_specs = pu.get_linespecs(color_scheme='bw',range_linewidth=[3,8],priority='linewidth')
>>> pu.linespecs_demo(line_specs)
Plots a pie chart from a single array.
>>> import plot_utils as pu
>>> pu.piechart(iris['species'])
Plots single or multiple time series data on the same plot nicely.
>>> import plot_utils as pu
>>> pu.plot_time_series(x) # plots single time series
>>> pu.plot_multiple_timeseries(X) # plots multiple time series
Plots data and error bounds on the same graph.
>>> import plot_utils as pu
>>> pu.plot_with_error_bounds(data,upper_bound,lower_bound)
No installation required.
Just download this repository, and you can put plot_utils.py
anywhere within your Python search path.
- Python 2.7 or 3.5 or 3.6
- matplotlib 1.5.0+, or 2.0.0+ (Version 2.1.0 is strongly recommended.)
- numpy: 1.11.0+
- pandas: 0.20.0+
- matplotlib/basemap: 1.0.7 (only if you want to plot the two choropleth maps)
The aesthetics of of the plot_utils
module are matplotlib-styled by default, but it doesn't mean that you can't use your favorite styles in seaborn or ggplot2.
Unlike some plotting packages that enforces their own styles and restrict users from customizing, users of this module can adjust the figure styles freely: either from within matplotlib (https://matplotlib.org/devdocs/gallery/style_sheets/style_sheets_reference.html), or import seaborn
and let seaborn take care of everything.
I did not built every function of this module entirely from scratch. I documented the sources that I referenced in the documentation of the corresponding functions.
(c) 2017-2018, Jian Shi
License: GPL v3.0