由于 pandas 的绘图功能不允许精细控制,所以最简单的方法是使用 mpl 的 subplotting 功能并通过循环处理来处理。不清楚您是要添加“est_fmc”行还是对其进行注释,所以我添加了该行。有关注释,请参阅此。
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import colors as mcolors
import numpy as np
import itertools
columns = ["Avg_1h_srf_mc", "Avg_1h_prof_mc", "Avg_10h_fuel_stick", "Avg_100h_debri_mc", "Avg_Daviesia_mc", "Avg_Euclaypt_mc", "obs_fmc_average", "obs_fmc_max",'est_fmc']
date_rng = pd.date_range('2017-01-01','2020-02-01', freq='1m')
df = pd.DataFrame({'date':pd.to_datetime(date_rng)})
for col in columns:
tmp = np.random.randint(0,200,(37,))
df = pd.concat([df, pd.Series(tmp, name=col, index=df.index)], axis=1)
fig, axs = plt.subplots(len(cols[:-1]), 1, figsize=(10,15), sharex=True)
fig.subplots_adjust(hspace=0.5)
colors = mcolors.TABLEAU_COLORS
for i,(col,cname) in enumerate(zip(columns[:-1], itertools.islice(colors.keys(),9))):
axs[i].plot(df['date'], df[col], label=col, color=cname)
axs[i].plot(df['date'], df['est_fmc'], label='est_fmc', color='tab:olive')
axs[i].set_yticks([0, 50, 100, 150, 200])
axs[i].grid()
axs[i].legend(loc='upper left', bbox_to_anchor=(1.02, 1.0))
plt.show()
