We can set options via a dictionary-like variable. The following function from the options.py
file in dautil
sets three options:
The first three options have to do with legends. The first option specifies rounded corners for the legend, the second options enables showing a shadow, and the third option makes the legend slightly transparent. The matplotlib rcdefaults()
function resets the configuration.
To demonstrate these options, let's use sample data made available by matplotlib. The imports are as follows:
The data is in a CSV file and contains stock price data for AAPL. Use the following commands to read the data and stores them in a pandas DataFrame
:
Resample the data to average monthly values as follows:
The full code is in the configure_matplotlib.ipynb
file in this book's code bundle:
The program plots the data and arbitrary upper and lower band with the default options, custom options, and after a reset of the options. I used the following helper class from the plotting.py
file of dautil
:
The class cycles through different line styles and line widths. Refer to the following plot for the end result: