-1

I have a large list of data points of x and y values that I need to put into a histogram with 40 bins but mathlibplot.hist is only letting me enter 1 variable with bins. I've tried hist2d as well but it's not very clean. Any help would be appreciated!

2 Answers2

0

As you have data points x and y, you can simply use hist method to plot histogram. The following code will help you to create a histogram.

plt.hist([x,y],bins=40, histtype='step',fill=True)
plt.show()

The histogram will look like the following:

enter image description here

If you want to change the style or give it title and labels, you can do it. Here is another histogram with unfilled bars.

Histogram 2

If you still face any problem, let me know then.

FAHAD SIDDIQUI
  • 631
  • 4
  • 22
-1

Maybe you can make use of matplotlib library to solve your purpose: It will be like imposing 2 histograms on top of each other. In the below code, I am trying to plot a histograms of y_train and predicted(X_train) in the same space. You can modify the variables as per your requirement.

import matplotlib.pyplot as plt

plt.hist(y_train, stacked=True,bins=40, label='Actual', alpha=0.5)
plt.hist(regressor.predict(X_train),bins=40, stacked=True, label='Predicted', alpha=0.5)
plt.legend(loc='best')
plt.show()

Hope this helps!

Sri2110
  • 335
  • 2
  • 19