matplotlib icon indicating copy to clipboard operation
matplotlib copied to clipboard

wrong legend in errorbar plot for pandas series

Open jkokorian opened this issue 11 years ago • 4 comments

When I make an errorbar plot from pandas Series, the names of the series appear twice in the legend. Once as a solid line, and once as a solid line with error bars. Explicitly setting the label argument replaces the label text for the solid line with errorbars.

%matplotlib inline
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
df = pd.DataFrame(data = np.random.rand(10,3),index=pd.Series(np.arange(0,20,2),name="number"),columns="A B C".split())
plt.errorbar(df.index,df.A,df.B)
plt.legend()

image

jkokorian avatar Nov 04 '15 10:11 jkokorian

Pretty sure this is because errorbar uses plot internally and now plot is smart enough to label it's self.

tacaswell avatar Nov 04 '15 17:11 tacaswell

As a quick work-around pass barsabove=True, I will have a patch for this shortly.

tacaswell avatar Nov 04 '15 18:11 tacaswell

Thanks!

jkokorian avatar Nov 04 '15 18:11 jkokorian

Shortly indeed!:)

jkokorian avatar Nov 04 '15 23:11 jkokorian