1

I have 2 dataframes. I make every df plot histogram looks like this:

df1
plt.show()

enter image description here

df2
plt.show()

enter image description here

if possible, I want to combine and show these histogram in single histogram but side by side with the different value. Is it possible?. my expected output looks like this Multiple Histogram (Example):

df_example
plt.show()

enter image description here

please give me advise.

Arief
  • 897
  • 1
  • 8
  • 17
  • working but my two histograms have different x and y value, one histogram too big and one to small result – Arief Jun 06 '18 at 05:18
  • you could try scaling or normalising the series before applying – Mohamed Thasin ah Jun 06 '18 at 05:19
  • how to do that? Forgive me because of I am newbie in python, thank you – Arief Jun 06 '18 at 05:21
  • try this solution https://stackoverflow.com/questions/26414913/normalize-columns-of-pandas-data-frame/29651514. it will give you a idea to solve your problem. once you apply the normalisation data will lies between 0 to 1 or -1 to 1. so your data is scaled. you could use this in histogram – Mohamed Thasin ah Jun 06 '18 at 05:24
  • thank you in advance, I'll try this solution. – Arief Jun 06 '18 at 05:37

1 Answers1

2

I think you need something like this,

import matplotlib.pyplot as plt
import  pandas as pd
df1=pd.DataFrame({"a":[1,2,4,2,1,43,23,12,54,12,344,45,212,12,43]})
df2=pd.DataFrame({"b":[223,234,234,342,652,234,652,121,345,456,234,467,234,568,237]})
plt.hist([df1['a'],df2['b']], color = ['b','g'],label=['a','b'])
plt.legend()
plt.show()

enter image description here

Mohamed Thasin ah
  • 9,418
  • 9
  • 43
  • 83