pandas - bar plot with different colors in python -
i have data :
import pandas pd import matplotlib.pyplot plt index={'a','b','c','d','e'} d={'typ':[1,2,2,2,1],'value':[10,25,15,17,13]} df=pd.dataframe(d,index=index)
i want plot dataframe in horizontal bars different colors reffering column 'typ'
you can use color
parameter of matplotlib's barh
function:
import pandas pd import matplotlib.pyplot plt index={'a','b','c','d','e'} d={'typ':[1,2,2,2,1],'value':[10,25,15,17,13]} df=pd.dataframe(d,index=index) # define colors each type colors = {1:'blue', 2:'red'} # plot bars plt.bar(range(len(df)), df['value'], align='center', color=[colors[t] t in df['typ']])
Comments
Post a Comment