4

I want to plot a histogram with a contour like this enter image description here

I found this picture in here, but after following the same procedure there I don't get the contour.

I saw this question in stack overflow but it draws an edge over each bar, and I want only the outer contour.

How can I draw this outer contour? (I'm running python 3)

Rohan Nadagouda
  • 462
  • 7
  • 18
bobsacameno
  • 765
  • 3
  • 10
  • 25

1 Answers1

10

The plot is probably produced with a different (i.e. older) matplotlib version. This can also be seen from the use of normed, which is deprecated in newer versions.

Here, you would explicitely set the edgecolor to black. ec="k", or longer, edgecolor="black".

import numpy as np
import matplotlib.pyplot as plt
plt.style.use('seaborn-white')

x1 = np.random.normal(0, 0.8, 1000)
x2 = np.random.normal(-2, 1, 1000)
x3 = np.random.normal(3, 2, 1000)

kwargs = dict(histtype='stepfilled', alpha=0.3, density=True, bins=40, ec="k")

plt.hist(x1, **kwargs)
plt.hist(x2, **kwargs)
plt.hist(x3, **kwargs);

plt.show()

enter image description here

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712