Customizing Your Plot#
import pandas as pd, matplotlib.pyplot as plt # import statement
df = pd.read_csv('https://raw.githubusercontent.com/kwaldenphd/elements-of-computing/main/book/data/ch10/air_quality_no2.csv', index_col=0, parse_dates=True) # load data
We can customize the plot using parameters that work directly within the Pandas
plotting function.
A few examples that set axis labels, plot title, etc.
# add axis labels and plot title
df['station_paris'].plot(xlabel = 'Paris Station', ylabel = 'No2 Level', title = 'Air Quality Level Readings')
# previous example, with grid set to True and color set to green
df['station_paris'].plot(xlabel = 'Paris Station', ylabel = 'No2 Level', title = 'Air Quality Level Readings', grid=True, color='green')
# sample example with adjusted font size
df['station_paris'].plot(xlabel = 'Paris Station', ylabel = 'No2 Level', title = 'Air Quality Level Readings', grid=True, color='green', fontsize=12)
Additional Resources#
For more parameters that can be passed to .plot()
: pandas.DataFrame.plot
Parameter |
Explanation |
---|---|
|
|
|
Default is |
|
Follows |
|
Follows |
|
Default is |
|
Title to use for the plot; can take a list with titles for corresponding subplots |
|
Default is |
|
Places legend on axis subplot |
|
Values to use for |
|
Values to use for |
|
Follows |
|
Follows |
|
Label for |
|
Label for |
|
Sets font size for tickmarks |
|
Sets |
|
Default is |
|
Default is |