Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the modern style matplotlib plots often seen in iPython Notebook examples?

Take this page, for example, a sample of which is posted below:

enter image description here

It has matplotlib examples with gray background and more subtle coloring, but when I'm running the same examples, I get the more traditionally colored plots with white background and strong colors. This also seems to be the style used in the pandas documentation.

How can I change the default style locally to match their style?

like image 573
Jimmy C Avatar asked Jan 19 '14 16:01

Jimmy C


People also ask

How do you display plots in Jupyter notebook?

Usually, displaying plots involves using the show() function from PyPlot. With Jupyter notebooks, this isn't necessary as the plots are displayed after running the cells containing the code that generates them. These plots are by default, displayed inline, which means, they're displayed in the notebook itself.

Which of the following is used to display plots on the Jupyter notebook?

The %matplotlib magic command sets up your Jupyter Notebook for displaying plots with Matplotlib. The standard Matplotlib graphics backend is used by default, and your plots will be displayed in a separate window.


2 Answers

If you read through the page you linked, just above the Plotting in Pandas section is the following line:

If you want to make your plots look pretty like mine, steal the matplotlibrc file from Huy Nguyen.

In the post is a link to this gist, which contains the matplotlibrc file. Make sure you read through the whole thing and customize it, as for example he has MacOSX as his backend, which you may want to change.

To use the file, save it as ~/.matplotlib/matplotlibrc and restart any running instances of IPython. Your plots should now look prettier :)

like image 60
MattDMo Avatar answered Sep 22 '22 00:09

MattDMo


As MattDMo mentioned, using a sane matplotlibrc really helps. The book "Probabilistic-Programming-and-Bayesian-Methods-for-Hackers" also uses a nice matplotlibrc. See this for some examples.

Recently I'm using the package seaborn instead of a custom matplotlibrc not only because it makes my plots look great, but also because it adds some functionality for visualizing distributions, linear models and time series.

like image 3
Stefan Avatar answered Sep 25 '22 00:09

Stefan