Painlessly create beautiful matplotlib plots.

Overview

Announcement

Thank you to everyone who has used prettyplotlib and made it what it is today! Unfortunately, I no longer have the bandwidth to maintain prettyplotlib. I recommend using seaborn. Using seaborn, to get the prettyplotlib style, do:

import seaborn as sns
sns.set(style='ticks', palette='Set2')

And to remove "chartjunk", do:

sns.despine()

If you have discrete pull requests, I will accept them, but I personally will no longer fix bugs.

If you are a biological scientist looking for ways to analyze your big-ish (20+ samples) data, check out my main project, flotilla.

Build Status

prettyplotlib

Python matplotlib-enhancer library which painlessly creates beautiful default matplotlib plots. Inspired by Edward Tufte's work on information design and Cynthia Brewer's work on color perception.

I truly believe that scientific progress is impeded when improper data visualizations are used. I spent a lot of time tweaking my figures to make them more understandable, and realized the scientific world could be a better place if the default parameters for plotting libraries followed recent advances in information design research. And thus prettyplotlib was born.

Requirements:

  • matplotlib. Can be installed via pip install matplotlib or easy_install matplotlib
  • brewer2mpl. Can be installed via pip install brewer2mpl or easy_install brewer2mpl

Comparison to matplotlib

matplotlib default plot
prettyplotlib default plot
matplotlib default scatter
prettyplotlib default scatter
matplotlib default bar
prettyplotlib default bar
matplotlib default hist
prettyplotlib default hist
matplotlib default hist
with grid
prettyplotlib default hist
with grid
matplotlib default boxplot
prettyplotlib default boxplot
matplotlib default pcolormesh
positive and negative data
prettyplotlib default pcolormesh
positive and negative data
matplotlib default pcolormesh
positive data only
prettyplotlib default pcolormesh
positive data only
matplotlib pcolormesh
negative-valued data with labels
prettyplotlib pcolormesh
negative-valued data with labels

Quotes

"Dis ain't no uglyplotlib" - Anonymous

Comments
  • PPL makes no difference to colour scheme - IPython 2.0.0 / Python 3.4 / PPL 0.1.7 / MPL 1.3.1

    PPL makes no difference to colour scheme - IPython 2.0.0 / Python 3.4 / PPL 0.1.7 / MPL 1.3.1

    I have a notebook started with --pylab inline and a script that looks like this:

    import prettyplotlib as ppl
    
    np.random.seed(12)
    
    fig, ax = plt.subplots(1)
    
    ppl.hist(ax, np.random.randn(1000))
    

    But the output seems to render using the default matplotlib colours:

    screen shot 2014-04-19 at 11 35 54

    Am I doing something wrong, or is there a version incompatibility somewhere?

    This is on Ubuntu 12.04, Python 3.4, and here is the output of pip --list:

    beautifulsoup4 (4.2.1) Bottleneck (0.8.0) brewer2mpl (1.4) Cython (0.20.1) deap (1.0.1) distribute (0.6.49) docutils (0.11) fastcluster (1.1.13) ipython (2.0.0) Jinja2 (2.7.2) lxml (3.3.5) MarkupSafe (0.21) matplotlib (1.3.1) nose (1.3.1) numexpr (2.4) numpy (1.8.1) numpydoc (0.5.dev) pandas (0.13.1) patsy (0.2.1) pip (1.5.4) prettyplotlib (0.1.7) psycopg2 (2.5.2) Pygments (1.6) pymc (3.0) pyparsing (2.0.2) python-dateutil (2.2) pytz (2014.2) pyzmq (14.1.1) scikit-learn (0.15-git) scipy (0.13.3) seaborn (0.3) setuptools (0.6c11) six (1.6.1) Sphinx (1.2.2) statsmodels (0.6.0) sympy (0.7.5) tables (3.1.1) Theano (0.6.0) tornado (3.2)

    opened by andrewclegg 13
  • Python 2.7: with ppl.pretty fails

    Python 2.7: with ppl.pretty fails

    import prettyplotlib as ppl
    with ppl.pretty:
      pass
    
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: __exit__
    
    opened by dpq 9
  • New release

    New release

    Hi @olgabot. Do you plan on uploading a new release on PyPI soon? I would like to have "pip install prettyplotlib" fetch the code with the Python 3 compatibility changes, instead of having to point pip to the GitHub repo.

    opened by gotgenes 8
  • `remove_chartjunk` will throw with `grid=['x','y']`

    `remove_chartjunk` will throw with `grid=['x','y']`

    Suggest adding for so that lines 403-405 become:

    if grid is not None:
        for g in grid:
            assert g in ('x', 'y')
            ax.grid(axis=g, color='white', linestyle='-', linewidth=0.5)
    
    opened by JefferyRPrice 8
  • Histogram with log scale

    Histogram with log scale

    When I create a histogram with a log scale, the y-axis is too large to show the available data. If I add a limit using ax.set_ylim(0, 25), the graph still does not show any data.

    import prettyplotlib as ppl
    import matplotlib.pyplot as plt
    import numpy as np
    
    np.random.seed(12)
    
    fig, ax = plt.subplots(1)
    
    ppl.hist(ax, np.random.randn(100), grid='y')
    ax.set_yscale('log')
    ax.set_ylim(0, 25)
    
    plt.show()
    

    screen shot 2014-01-31 at 14 36 18

    opened by domoritz 6
  • Colors are not set correctly

    Colors are not set correctly

    It looks like with matplotlib 1.3.1 plotting doesn't pick up the right colors.

    numpy==1.7.1 prettyplotlib==0.1.7 brewer2mpl==1.4 matplotlib==1.3.1

    I'm looking at the example from https://github.com/olgabot/prettyplotlib/wiki/Examples-with-code#plot-lines-eg-time-series-with-a-legend

    import prettyplotlib as ppl
    import numpy as np
    
    # prettyplotlib imports 
    import matplotlib.pyplot as plt
    import matplotlib as mpl
    from prettyplotlib import brewer2mpl
    
    # Set the random seed for consistency
    np.random.seed(12)
    
    fig, ax = plt.subplots(1)
    
    # Show the whole color range
    for i in range(8):
        y = np.random.normal(size=1000).cumsum()
        x = np.arange(1000)
    
        # For now, you need to specify both x and y :(
        # Still figuring out how to specify just one
        ppl.plot(ax, x, y, label=str(i), linewidth=0.75)
    
    ppl.legend(ax)
    
    fig.savefig('plot_prettyplotlib_default.png')
    

    Creates the following image:

    plot_prettyplotlib_default

    opened by domoritz 5
  • Can't install on OSX 10.9.2

    Can't install on OSX 10.9.2

    When I try to install, I get the following error message:

    clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]

    This seems to be problem with the recently updated xcode. A temporary solution is given here (http://kaspermunck.github.io/2014/03/fixing-clang-error/). Would it be possible to implement it into prettypot?

    opened by RachelBunder 5
  • pip sometimes fetches wrong distribution of prettyplotlib

    pip sometimes fetches wrong distribution of prettyplotlib

    In #13, @ilblackdragon mentioned that pip can sometimes fetch the wrong distribution file of prettyplotlib. More specifically

    • pip seems to be attempting to fetch the OS X 10.9 tarball for platforms that are not OS X.
    • using pip inside a virtualenv does not seem to suffer from this problem

    @ilblackdragon, is there a chance that the pip versions are different for your system-wide installation than the ones inside your virtualenvs?

    @olgabot Is there a reason for a tarball built specifically for OS X 10.9? prettyplotlib has no extension modules that need to be built for any specific platform and is a pure Python package. I see that it's meant to be untarred at the root directory so that it unpacks into /usr/local/lib/python2.7/site-packages/prettyplotlib, but this isn't even the right directory to unpack to for most OS X users since OS X uses the whole "Framework Python" layout (unless the user has explicitly installed a non-Framework Python via MacPorts or Homebrew). I'm not sure this extra tarball is helpful and it seems detrimental in the case of confusing pip on which tarball it should fetch.

    opened by gotgenes 5
  • Added an rc_context decorator to preserve rcParams.

    Added an rc_context decorator to preserve rcParams.

    Hi Olga,

    Thanks for all the work you've put in prettyplotlib! I've given it a quick try over the last week and I really liked the enhanced looks of my graphs.

    I tried to fix Issue #15 (making importing prettyplotlib side effect-free) since I wanted to use it along regular pyplot -using code. This solution fixes it, and seems to passes tests. Hope it can be useful!

    opened by williampw 5
  • Enhancement: boxplot2

    Enhancement: boxplot2

    Hi Olga, I recently attended a conference where a number of immunologists showed a variant of a boxplot like this one http://www.nature.com/nm/journal/v12/n12/images/nm1511-F1.jpg So I proceed to hack the matplotlib's default boxplot to resemble this pretty creature. An example rendering is attached below and a working example is a part of the commit. plot Would you like to incorporate that into prettyplotlib or are you happy with the boxplot from matplotlib? I realize that the code is probably somewhat incomplete/hacky so I'll gladly make changes.

    opened by jandom 4
  • Providing complete pyplot interface?

    Providing complete pyplot interface?

    When using prettyplotlib you have to think before every function call whether it is a plotting command implemented in prettyplotlib or some other command solely implemented in pyplot (of matplotlib). These cognitive resources could be spared if it was possible to completely switch over to prettyplotlib for all functions.

    To give an example, it would be nice instead of writing

    import matplotlib.pyplot as plt
    import prettyplotlib as ppl
    
    # produce data to plot
    
    ppl.plot(x, y)
    plt.xlabel('$x$')
    plt.ylabel('$y$')
    

    to be able to write

    ppl.plot(x, y)
    ppl.xlabel('$x$')
    ppl.ylabel('$y$')
    

    Are any other people considering this a worthwhile feature?

    For implementing this I see two possibilities:

    1. For each pyplot function implement one function in prettyplotlib calling the pyplot function. This could be quite some work and might break when the pyplot API changes.
    2. Use this “hack” to dynamically map calls to functions not defined in prettyplotlib to pyplot. I am not completely sure what problems could occur with this approach. I think, it might prevent code completion in some editors or syntax checking might be less accurate.
    opened by jgosmann 4
  • Fix Issue#100

    Fix Issue#100

    To fix KeyError in prettyplotlib/colors.py, I have modified following;

    • Use axes.prop_cycle instead of axes.color_cycle since rcParams of matplotlib requires prop_cycle.

    • Use cycler library to be consistent with the matplotlibrc official template. https://github.com/matplotlib/matplotlib/blob/master/matplotlibrc.template

    • Use hex_colors instead of mpl_colors to be consistent with the matplotlibrc official template too.

    opened by genkioffice 0
  • axis labels at edges

    axis labels at edges

    Hi,

    Great job with this module. Really easy to use. One thing though. I would like to have my axis labels not centered, i.e., at the edges of the bins. Any idea how to achieve that with this module?

    opened by Marston 0
  • ERROR when running example hist

    ERROR when running example hist

    Enviroment: anaconda latest (Python 2.7.13 |Anaconda 4.4.0 (64-bit)| (default, Dec 20 2016, 23:09:15) ) installed using pip

    >>> ppl.hist(ax, np.random.randn(1000))
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/canicula/anaconda2/lib/python2.7/site-packages/prettyplotlib/colors.py", line 35, in wrapper
        return func(*args, **kwargs)
      File "/home/canicula/anaconda2/lib/python2.7/site-packages/prettyplotlib/_hist.py", line 18, in hist
        color_cycle = ax._get_lines.color_cycle
    AttributeError: '_process_plot_var_args' object has no attribute 'color_cycle'
    
    
    opened by bingosxs 0
  • Can't create histogram (AttributeError: '_process_plot_var_args' object has no attribute 'color_cycle')

    Can't create histogram (AttributeError: '_process_plot_var_args' object has no attribute 'color_cycle')

    Hey there!

    fig, axes = plt.subplots(1)
    ppt.hist(axes, df.hour)
    
    ---------------------------------------------------------------------------
    AttributeError                            Traceback (most recent call last)
    <ipython-input-201-26997647cd59> in <module>()
          1 fig, axes = plt.subplots(1)
    ----> 2 ppt.hist(axes, df.hour)
    
    /usr/local/lib/python3.6/site-packages/prettyplotlib/colors.py in wrapper(*args, **kwargs)
         33     def wrapper(*args, **kwargs):
         34         with mpl.rc_context(rc=rcParams):
    ---> 35             return func(*args, **kwargs)
         36     return wrapper
         37 
    
    /usr/local/lib/python3.6/site-packages/prettyplotlib/_hist.py in hist(*args, **kwargs)
         16     ax, args, kwargs = maybe_get_ax(*args, **kwargs)
         17 
    ---> 18     color_cycle = ax._get_lines.color_cycle
         19     # Reassign the default colors to Set2 by Colorbrewer
         20     if iterable(args[0]):
    
    AttributeError: '_process_plot_var_args' object has no attribute 'color_cycle'
    

    When I try to make the barplot, everything's the same :\

    opened by demidovakatya 0
  • matplotlib style

    matplotlib style

    Hello I wonder if one of the style in matplotlib.syle does the same ? You advice to use seaborn instead of matplotlib and several style seems to be extracted from seaborn

    ['bmh',
     'fivethirtyeight',
     'seaborn-darkgrid',
     'seaborn-talk',
     'seaborn-colorblind',
     'seaborn-dark-palette',
     'seaborn-notebook',
     'seaborn-paper',
     'seaborn-muted',
     'seaborn-poster',
     'seaborn-white',
     'dark_background',
     'seaborn-whitegrid',
     'seaborn-deep',
     'ggplot',
     'seaborn-bright',
     'grayscale',
     'classic',
     'seaborn-ticks',
     'seaborn-pastel',
     'seaborn-dark']
    

    Thank you for your code and help

    opened by gVallverdu 1
Owner
Olga Botvinnik
peppy computational biologist
Olga Botvinnik
A python package for animating plots build on matplotlib.

animatplot A python package for making interactive as well as animated plots with matplotlib. Requires Python >= 3.5 Matplotlib >= 2.2 (because slider

Tyler Makaro 394 Dec 18, 2022
A python package for animating plots build on matplotlib.

animatplot A python package for making interactive as well as animated plots with matplotlib. Requires Python >= 3.5 Matplotlib >= 2.2 (because slider

Tyler Makaro 356 Feb 16, 2021
Easily convert matplotlib plots from Python into interactive Leaflet web maps.

mplleaflet mplleaflet is a Python library that converts a matplotlib plot into a webpage containing a pannable, zoomable Leaflet map. It can also embe

Jacob Wasserman 502 Dec 28, 2022
MPL Plotter is a Matplotlib based Python plotting library built with the goal of delivering publication-quality plots concisely.

MPL Plotter is a Matplotlib based Python plotting library built with the goal of delivering publication-quality plots concisely.

Antonio López Rivera 162 Nov 11, 2022
The plottify package is makes matplotlib plots more legible

plottify The plottify package is makes matplotlib plots more legible. It's a thin wrapper around matplotlib that automatically adjusts font sizes, sca

Andy Jones 97 Nov 4, 2022
🐍PyNode Next allows you to easily create beautiful graph visualisations and animations

PyNode Next A complete rewrite of PyNode for the modern era. Up to five times faster than the original PyNode. PyNode Next allows you to easily create

ehne 3 Feb 12, 2022
Create a table with row explanations, column headers, using matplotlib

Create a table with row explanations, column headers, using matplotlib. Intended usage was a small table containing a custom heatmap.

null 4 Aug 14, 2022
Create matplotlib visualizations from the command-line

MatplotCLI Create matplotlib visualizations from the command-line MatplotCLI is a simple utility to quickly create plots from the command-line, levera

Daniel Moura 46 Dec 16, 2022
Make sankey, alluvial and sankey bump plots in ggplot

The goal of ggsankey is to make beautiful sankey, alluvial and sankey bump plots in ggplot2

David Sjoberg 156 Jan 3, 2023
Python scripts to manage Chia plots and drive space, providing full reports. Also monitors the number of chia coins you have.

Chia Plot, Drive Manager & Coin Monitor (V0.5 - April 20th, 2021) Multi Server Chia Plot and Drive Management Solution Be sure to ⭐ my repo so you can

null 338 Nov 25, 2022
Plot, scatter plots and histograms in the terminal using braille dots

Plot, scatter plots and histograms in the terminal using braille dots, with (almost) no dependancies. Plot with color or make complex figures - similar to a very small sibling to matplotlib. Or use the canvas to plot dots and lines yourself.

Tammo Ippen 207 Dec 30, 2022
Example scripts for generating plots of Bohemian matrices

Bohemian Eigenvalue Plotting Examples This repository contains examples of generating plots of Bohemian eigenvalues. The examples in this repository a

Bohemian Matrices 5 Nov 12, 2022
Moscow DEG 2021 elections plots

Построение графиков на основе публичных данных о ДЭГ в Москве в 2021г. Описание Скрипты в данном репозитории позволяют собственноручно построить графи

null 9 Jul 15, 2022
This plugin plots the time you spent on a tag as a histogram.

This plugin plots the time you spent on a tag as a histogram.

Tom Dörr 7 Sep 9, 2022
A minimal Python package that produces slice plots through h5m DAGMC geometry files

A minimal Python package that produces slice plots through h5m DAGMC geometry files Installation pip install dagmc_geometry_slice_plotter Python API U

Fusion Energy 4 Dec 2, 2022
Generate "Jupiter" plots for circular genomes

jupiter Generate "Jupiter" plots for circular genomes Description Python scripts to generate plots from ViennaRNA output. Written in "pidgin" python w

Robert Edgar 2 Nov 29, 2021
A Python function that makes flower plots.

Flower plot A Python 3.9+ function that makes flower plots. Installation This package requires at least Python 3.9. pip install

Thomas Roder 4 Jun 12, 2022
Standardized plots and visualizations in Python

Standardized plots and visualizations in Python pltviz is a Python package for standardized visualization. Routine and novel plotting approaches are f

Andrew Tavis McAllister 0 Jul 9, 2022
YOPO is an interactive dashboard which generates various standard plots.

YOPO is an interactive dashboard which generates various standard plots.you can create various graphs and charts with a click of a button. This tool uses Dash and Flask in backend.

ADARSH C 38 Dec 20, 2022