小编sas*_*ner的帖子

Plot dataframe then add vertical lines; how get custom legend text for all?

I can plot a dataframe (2 "Y" values) and add vertical lines (2) to the plot, and I can specify custom legend text for either the Y values OR the vertical lines, but not both at the same time.

import pandas as pd
import matplotlib.pyplot as plt

d = {'x' : [1., 2., 3., 4.], 'y1' : [8., 6., 4., 2.], 'y2' : [-4., 13., 2.2, -1.1]}
df = pd.DataFrame(d)
ax = df.plot(x='x', y=['y1'], linestyle='-', color='b')
df.plot(x='x', y=['y2'], linestyle='--', color='y', …
Run Code Online (Sandbox Code Playgroud)

python matplotlib pandas

5
推荐指数
1
解决办法
2157
查看次数

标签 统计

matplotlib ×1

pandas ×1

python ×1