Configuring Styles
matplotlib
provides two ways to change the default styling settings. The first is with a file called matplotlibrc
, which defines all the styles that matplotlib
should use when plotting.
This is great if you want to change the look of your plots without setting axes properties manually each time or if you want to share your styles with a team of developers. The second approach is interactive configuration.
00:00
Matplotlib provides two ways to change the default styling settings. The first is with a file called matplotlibrc
, which defines all the styles Matplotlib should use when plotting.
00:16
This is great if you want to change the look of your plots without setting Axes
properties manually each time, or if you want to share your styles with a team of developers.
00:28 If you’re interested in that approach, you can see the link in the video notes down below to learn more. In this video, we’ll take a look at the other approach, which is interactive configuration.
00:42
I’m here in an interactive shell, but you can do this all within your Python scripts if you’d prefer. pyplot
contains an rcParams
object that represents a Python dictionary of settings.
00:57
Every object that starts with rc
is a way to interact with our plot styles and settings. rcdefaults
restores the rc parameters from Matplotlib’s internal defaults, which are listed at rcParamsDefault
. rc()
is used for setting parameters interactively. And rcParams
is a mutable dictionary-like object that lets us manipulate settings directly.
01:29
This dictionary also holds settings you have saved in a matplotlibrc
file if you’ve got one on your system.
01:39
Let’s use rc()
to set the default line color and line width. I’ll take plt.rc('lines', linewidth=2, color='r')
, for red.
01:59
Now all of our lines will be red and a width of two—well, at least for this interactive session. pyplot
also comes with a bunch of predefined styles that completely change the way our plots look.
02:15
We can view all of them with plt.style.available
. Let’s use 'fivethirtyeight'
, which mimics the style of fivethirtyeight.com, which has got a very unique style.
02:33
We can do that with plt.styles.use('fivethirtyeight')
. Now our plots will look something like this.
Become a Member to join the conversation.