import pandas as pd import numpy as np
import matplotlib.pyplot as plt
df = pd.DataFrame({ ‘color‘: [‘red‘,‘red‘,‘red‘,‘blue‘,‘blue‘,‘blue‘], ‘x‘: [0,1,2,3,4,5],‘y‘: [0,1,2,9,16,25] })
实现
fig, ax = plt.subplots() for key, group in df.groupby([‘color‘]): ax = group(ax=ax, kind=‘line‘, x=‘x‘, y=‘y‘, c=key, label=key) plt.legend() plt.show()
也可以
ax = None for key, group in df.groupby([‘color‘]): ax = group(ax=ax, kind=‘line‘, x=‘x‘, y=‘y‘, c=key, label=key) plt.legend() plt.show()
原文:https://www.cnblogs.com/spaceapp/p/11771945.html