python - Double graph with matplotlib: Attribute error -
i have got pandas dataframe this:
nan 0 ingredient contribution count 0 0.0 cracker 0.088844873 11 1 2.0 water 0.044386494 125 2 3.0 oil 0.034567456 10 3 4.0 flour 0.030855063 186 ...
i create double figure looks this:
the code tried:
import matplotlib.pyplot plt #importing libraries import numpy np plt.figure(1) #creating empty figure t = np.arange(0.0, 2.0, 0.01) fig_contr = df[['ingredient','contribution']] #selecting columns fig_count = df[['ingredient','count']] plt.subplot(211) #creating subplot plt.plot(t, fig_contr) #plotting subplot plt.subplot(212) plt.plot(t, fig_count)
but error: attributeerror: 'dataframe' object has no attribute 'find
how should create figure obtain?
one possible solution use series.plot.bar
:
plt.figure(1) #creating empty figure df.set_index('ingredient', inplace=true) #set index column ingredient fig_contr = df['contribution'] #selecting columns fig_count = df['count'] plt.subplot(211) #creating subplot fig_contr.plot.bar() #plotting subplot plt.subplot(212) fig_count.plot.bar() plt.show()
you can change orientation of labels of axis x:
plt.figure(1) #creating empty figure df.set_index('ingredient', inplace=true) fig_contr = df['contribution'] #selecting columns fig_count = df['count'] plt.subplot(211) #creating subplot fig_contr.plot.bar(rot=0) #plotting subplot plt.subplot(212) fig_count.plot.bar(rot=0) plt.show()
Comments
Post a Comment