绘制PandasDatafarme列时,是否可以使用Dataframe列名作为图例标签,而不是显式指定标签?
示例:
import matplotlib.pyplot as plt
import pandas as pd
df = pd.DataFrame(data={'col1': [0, 2, 1, 3],
'col2': [9,7,8,9]},
index=[0, 1, 2, 3])
f = plt.figure()
ax = f.subplots()
ax.plot(df['col1'], label='col1') # How to not explicitly specify label?
# ax.plot(df['col1']) # This does not produce a legend label
ax.legend()
1条答案
按热度按时间inb24sb21#
使用Pandas绘图API: