Ggplot2 graph style with matplotlib

Gg2plot is an amazing library to plot and it’s available for R to create stunning graphs. GGplot2 takes a different approach from the classic library, and instead of offering a classic line/points approach permits to combine these elements (example), which is a similar root took by D3js. If you are using the scientific python stack (matplotlib, numpy, scipy, ipython) you have the very good matplotlib to plot and have all your graph app.

For example a bunch of sin and cosine generated by the following code:

https://gist.github.com/mattions/5330631

look like this:

classic_matplotlib

Instead if we set up a ggplot2 style, the graph looks like this:

matplotlib_ggplot2_style

You may prefer one or the other. Anyway if you like the last one, just download this matplotlibrc and save it as ~/.matplotlib/matplotlibrc, and all your graph will have that style as default.

The matplotlibrc has been inspired by this post, I’ve just updated with the latest matplotlibrc from matplotlib 1.2.1 version.

Have fun!

Edit: Bonus plot, code in the gist.

exp_and_log

2 Comments

  1. How would you update the matplotlib rcParams in a specific plotting script to change the size of the xtick labels for example. I can’t seem to override the params once I have installed the matplotlibrc file you have provided.

    • The rcParams are loaded as dictionary

      import matplotlib
      matplotlib.rcParams # dictionary with all the rcParams.

      however, if you need to change the ticks for only one plot, maybe you can use plt.xticks or similar to achieve your goal.

Leave a Reply