I am using matplotlibs ggplot style for plotting and want to overide only specific standard parameters such as the color of the xticklabels, grid background color and linewidth.
import numpy as np
import pandas as pd
import matplotlib
# changing matplotlib the default style
matplotlib.style.use('ggplot')
# dataframe plot
df = pd.DataFrame(np.random.randn(36, 3))
df.plot()
returns:
I know I can set single properties for axes-objects like this:
ax.set_axis_bgcolor('red')
But how can I override the default propertiers (e.g. label-color, background color and linewidth to have them in all plots?
Thanks in advance!
To make the matplotlib similar to the ggplot you can pass on a style argument. There is a ggplot style already available but I personally prefer the white background as in ggplot's theme_bw .
The plots are pretty much identical, aesthetics-wise, but ggplot2 beats Matplotlib once again when it comes to code amount. It's also much easier to format the x-axis to display dates in R than it is in Python.
This example demonstrates the "ggplot" style, which adjusts the style to emulate ggplot (a popular plotting package for R). These settings were shamelessly stolen from [1] (with permission).
The new default colormap used by matplotlib. cm. ScalarMappable instances is 'viridis' (aka option D).
You could use rcParams
to set parameters globally. e.g.
import numpy as np
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
# changing matplotlib the default style
matplotlib.style.use('ggplot')
plt.rcParams['lines.linewidth']=3
plt.rcParams['axes.facecolor']='b'
plt.rcParams['xtick.color']='r'
# dataframe plot
df = pd.DataFrame(np.random.randn(36, 3))
df.plot()
plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With