ggplot styles in Python

If you need to see available styles :

import matplotlib.pyplot as plt

print(plt.style.available)

This will print available styles.

And use this link to select the style you prefer

https://tonysyu.github.io/raw_content/matplotlib-style-gallery/gallery.html


Update: If you have matplotlib >= 1.4, there is a new style module which has a ggplot style by default. To activate this, use:

from matplotlib import pyplot as plt
plt.style.use('ggplot')

To see all the available styles, you can check plt.style.available.


Similarly, for seaborn styling you can do:

plt.style.use('seaborn-white')

or, you can use seaborn's own machinery to set up the styling:

import seaborn as sns
sns.set()

The set() function has more options to select a specific style (see docs). Note that seaborn previously did the above automatically on import, but with the latest versions (>= 0.8) this is no longer the case.


If you actually want a ggplot-like syntax in Python as well (and not only the styling), take a look at the plotnine package, which is a grammar of graphics implementation in Python with a syntax very similar to R's ggplot2.


Note: the old answer mentioned to do pd.options.display.mpl_style = 'default' . This was however deprecated in pandas in favor of matplotlib's styling using plt.style(..), and in the meantime this functionality is even removed from pandas.


For the themes in python-ggplot, you can use them with other plots:

from ggplot import theme_gray
theme = theme_gray()
with mpl.rc_context():
    mpl.rcParams.update(theme.get_rcParams())

    # plotting commands here

    for ax in plt.gcf().axes:
        theme.post_plot_callback(ax)