ggplot styles in Python

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)