I have a pandas dataframe with user information. I would like to plot the age of users as both a kind=\'kde\' and on kind=\'hist\' on
pd.DataFrame.plot() returns the ax it is plotting to. You can reuse this for other plots.
Try:
ax = member_df.Age.plot(kind='kde')
member_df.Age.plot(kind='hist', bins=40, ax=ax)
ax.set_xlabel('Age')
example
I plot hist first to put in background
Also, I put kde on secondary_y axis
import pandas as pd
import numpy as np
np.random.seed([3,1415])
df = pd.DataFrame(np.random.randn(100, 2), columns=list('ab'))
ax = df.a.plot(kind='hist')
df.a.plot(kind='kde', ax=ax, secondary_y=True)
response to comment
using subplot2grid. just reuse ax1
import pandas as pd
import numpy as np
ax1 = plt.subplot2grid((2,3), (0,0))
np.random.seed([3,1415])
df = pd.DataFrame(np.random.randn(100, 2), columns=list('ab'))
df.a.plot(kind='hist', ax=ax1)
df.a.plot(kind='kde', ax=ax1, secondary_y=True)