Each Answer to this Q is separated by one/two green lines.
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
Similarly, for seaborn styling you can do:
or, you can use
seaborn‘s own machinery to set up the styling:
import seaborn as sns sns.set()
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)
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
Jan Katins’s answer is good, but the python-ggplot project seems to have become inactive. The plotnine project is more developed and supports an analogous, but superficially different, solution:
from plotnine import theme_bw import matplotlib as mpl theme = theme_bw() with mpl.rc_context(): mpl.rcParams.update(theme.rcParams)