Skip to content

jaga-ram48/python-plot-utilities

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python plotting utilities: plot_utils

Author: Jian Shi

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]
    • and a get_linespecs() function that generates distinct color/linestyle/linewidth combinations for plotting many lines [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]

Gallery

1. Three-dimensional histograms

Plots 3D histograms. Useful for comparing multiple distributions.

>>> import plot_utils as pu
>>> pu.histogram3d(X)  # X is the dataset to be visualized

[doc], [example]

histogram_3d

2. Choropleth map (state level)

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)

[doc], [example]

choropleth_map_state

3. Choropleth map (county level)

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)

[doc], [example]

choropleth_map_county

4. Correlation matrix (aka, covariance matrix)

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)

[doc], [example]

5. "Bin-and-mean" plot

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')

[doc], [example]

6.1. get_colors() function

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)

[doc], [example]

6.2. get_linespecs() function

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)

[doc], [example]

7. Pie chart

Plots a pie chart from a single array.

>>> import plot_utils as pu
>>> pu.piechart(iris['species'])

[doc], [example]

8. Time series plotting

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

[doc], [example]

9. Plot with error bounds

Plots data and error bounds on the same graph.

>>> import plot_utils as pu
>>> pu.plot_with_error_bounds(data,upper_bound,lower_bound)

[doc], [example]

Installation

No installation required.

Just download this repository, and you can put plot_utils.py anywhere within your Python search path.

Dependencies

  • 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)

Aesthetics

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.

References

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.

Copyright and license

(c) 2017-2018, Jian Shi

License: GPL v3.0

About

A Python library for elegant data visualization

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages