You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to plot a pandas Series with pyplot.bar(), it seems Series whose first index is not 0 cause a TypeError: only size-1 arrays can be converted to Python scalars exception when the bottom argument is given. When bottom is not given, bar width is not uniform as expected.
Code for reproduction
importpandasaspdimportmatplotlib.pyplotaspltdf=pd.DataFrame({'i':[1,4,4,4,6,6], 'n':[3,5,1,2,3,4]})
ix=df.index%2==0plt.figure()
# produces expected plot with bars offset from x axisplt.bar(x=df.loc[ix,'i'], height=df.loc[ix, 'n'], bottom=df.loc[ix, 'i'])
plt.figure()
# produces expected plotplt.bar(x=df.loc[ix,'i'], height=df.loc[ix, 'n'])
ix=df.index%2==1plt.figure()
# the following fails with `TypeError`# plt.bar(x=df.loc[ix,'i'], height=df.loc[ix, 'n'], bottom=df.loc[ix, 'i'])# converting to a list fixes the issue and produces the expected outcome.# note that casting both x and bottom to list is required to produce expected outcome.plt.bar(x=list(df.loc[ix,'i']), height=df.loc[ix, 'n'], bottom=list(df.loc[ix, 'i']))
plt.figure()
# produces plot with unexpected bar widthplt.bar(x=df.loc[ix,'i'], height=df.loc[ix, 'n'])
# again, converting to list produces expected outcomeplt.figure()
plt.bar(x=list(df.loc[ix,'i']), height=df.loc[ix, 'n'])
Bug report
Bug summary
When trying to plot a pandas Series with pyplot.bar(), it seems Series whose first index is not 0 cause a
TypeError: only size-1 arrays can be converted to Python scalars
exception when thebottom
argument is given. Whenbottom
is not given, bar width is not uniform as expected.Code for reproduction
Matplotlib version
print(matplotlib.get_backend())
): MacOSXInstalled from conda, using default channel.
The text was updated successfully, but these errors were encountered: