I'm trying to plot my data, however pandas uses the column label which I need to override in the legend. I thought the label keyword would change this, but it seems to have no effect. Googling shows that this was a bug in the 0.15 version, but I have 0.25 now. Does anyone know of a way around this?
Sample code:
x = pd.DataFrame(list(range(2,513, 2)), columns=['x'])
y = pd.DataFrame(np.random.rand(256), columns=['y'])
df = pd.concat([x, y], axis=1)
df = df.set_index(['x'])
df.plot(label='Random')
I would expect the legend to then list 'Random' as label for the curve.
It seems like the labels are created automatically from the series names. You can rename your y
series before plotting as a workaround, ie.:
df.y.rename('Random').plot(legend=True)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With