pandas - How to plot histogram with x and y axis from dataframe in python -


i plot histogram pandas dataframe. have 4 columns in dataframe, pick 2 of them , plot it. plug in xaxis , yaxis values , draw 3 sub historgrams.

here's how code looks like:

fig = plt.figure(figsize=(9,7), dpi=100)  h = plt.hist(x=df_mean_h ['id'], y=df_mean_h ['mean'],  color='red', label='h')  c = plt.hist(x=df_mean_c ['id'], y=df_mean_c ['mean'],  color='blue', label='c')  o = plt.hist( x=df_mean_o['id'], y=df_mean_o ['mean'],  color='green', label='o')  plt.show() 

when try see histogram, displays nothing on screen. how should fix code?

  1. you need show plot plt.show()

  2. plt.hist() works differently scatter or series. can't send x= , y=

https://matplotlib.org/1.2.1/examples/pylab_examples/histogram_demo.html

to make example work, send plt.hist single column create chart:

import numpy np import matplotlib.pyplot plt import pandas pd d = {'one' : pd.series([1., 2., 3.], index=['a', 'b', 'c']),  'two' : pd.series([1., 2., 3.], index=['a', 'b', 'c'])} df = pd.dataframe(d) fig = plt.figure(figsize=(9,7), dpi=100)  plt.hist(df['two'])  plt.show() 

Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -