- For those using
pandas.DataFrame.plot()
, matplotlib.axes.Axes
is returned when creating a plot from a dataframe. As such, the dataframe plot can be assigned to a variable, ax
, which enables the usage of the associated formatting methods.
- The default plotting backend for
pandas
, is matplotlib
.
import pandas as pd
# test dataframe
data = {'a': range(20), 'date': pd.bdate_range('2021-01-09', freq='D', periods=20)}
df = pd.DataFrame(data)
# plot the dataframe and assign the returned axes
ax = df.plot(x='date', color='green', ylabel='values', xlabel='date', figsize=(8, 6))
# set various colors
ax.spines['bottom'].set_color('blue')
ax.spines['top'].set_color('red')
ax.spines['right'].set_color('magenta')
ax.spines['left'].set_color('orange')
ax.xaxis.label.set_color('purple')
ax.yaxis.label.set_color('silver')
ax.tick_params(colors='red', which='both') # 'both' refers to minor and major axes
![enter image description here](https://i.stack.imgur.com/OmyHe.png)