python - Plot duplication in Pandas Plot() -
there issue plot() function in pandas
import numpy np import pandas pd import matplotlib.pyplot plt df = pd.dataframe(np.random.randn(8, 4), columns=['a', 'b', 'a', 'b']) ax = df.plot() ax.legend(ncol=1, bbox_to_anchor=(1., 1, 0., 0), loc=2 , prop={'size':6})
this make plot many lines. note half on top of each other. seems have axis because when not use them issue goes away.
import numpy np import pandas pd import matplotlib.pyplot plt df = pd.dataframe(np.random.randn(8, 4), columns=['a', 'b', 'a', 'b']) df.plot()
update
while not idea use case issue can fixed using multiindex
columns = pd.multiindex.from_arrays([np.hstack([ ['left']*2, ['right']*2]), ['a', 'b']*2], names=['high', 'low']) df = pd.dataframe(np.random.randn(8, 4), columns=columns) ax = df.plot() ax.legend(ncol=1, bbox_to_anchor=(1., 1, 0., 0), loc=2 , prop={'size':16})
it has duplication of column names, not ax
@ (if call plt.legend
after second example see same lines). having multiple columns same name confusing call dataframe.plot_frame
.
if change columns ['a', 'b', 'c', 'd']
instead, it's fine.
Comments
Post a Comment