0

I'm doing a project on the Boston Housing dataset and i'm trying to plot a distribution line on top of the histogram

Histogram:

# visualize the target variable in a histogram

# draw a mean line
plt.axvline(boston_data.MEDV.mean(), color='k', linestyle='dashed', linewidth=1)
### REMOVED min_ylim, max_ylim = plt.ylim()
plt.text(boston_data.MEDV.mean()*1.1, max_ylim*35, 'Mean: {:.2f}'.format(boston_data.MEDV.mean()))

# show the histogram for our target variable
boston_data.MEDV.hist(bins=50)

Distribution Line:

# draw a distribution line
s = boston_data['MEDV']
ax = s.plot.kde()

Can the line be drawn on top of the histogram?

thx in advance

(EDIT) This is what the plot looks like and what i would like to do is draw a distribution line on top of the histogram to show its a normal distribution (despite some outliers)

enter image description here

laminado
  • 69
  • 1
  • 3
  • 11
  • 1
    I don't understand this question. Have you tried your code? What was the outcome? Did the graph not meet your expectations? Did you receive any error messages? We don't have your data set, we cannot know. And what library do use - matplotlib or plotly? You tagged both. – Mr. T Jan 18 '21 at 10:40
  • 3
    @Mr.T It seems OP is using matplotlib's as well as pandas plotting. And probably gets confused that the scale of a kde-curve doesn't match an unnormalized histogram. The logical solution would be to use seaborn's `sns.histplot(boston_data['MEDV'], stat='count', kde=True, ....)`. The `plotly` tags looks like a mistake. – JohanC Jan 18 '21 at 10:51
  • @JohanC Yeah, no reason for the `plotly` tag so I removed it. – vestland Jan 18 '21 at 12:36

0 Answers0