Block 7: Plot histogram and Gaussian
s7 · run_code migrateReplace deprecated 'normed=True' with 'density=True' in plt.hist() call to match current matplotlib API.
@@ -1,4 +1,4 @@
# plot a histogram of the sample
-plt.hist(sample, bins=50, histtype="stepfilled", alpha=0.3, normed=True)
+plt.hist(sample, bins=50, histtype="stepfilled", alpha=0.3, density=True)
# plot a best-fit Gaussian
Sources
- normed has been deprecated for matplotlib histograms but not for pandas · Issue #24881 · pandas-dev/pandas · GitHub
This falls in line with the old matplotlib style. However the new matplotlib style has deprecated `normed` and replaced it with `density`.
- deprecated matplotlib keyword 'normed' · Issue #16 · dirac-institute/CMNN_Photoz_Estimator · GitHub
On running a command line example from the demo.ipynb I got an error: `AttributeError: 'Polygon' object has no property 'normed'` and looking into it I see that the matplotlib.pyplot.hist keyword 'normed' is now deprecated as of v1.6.0: <https://numpy.org/doc/stable/reference/generated/numpy.histogram.html#numpy.histogram> However, the fix seems pretty easy, as `normed` was replaced by `density` and now handles uneven bins in addition to evenly spaced bins.