The counts behind a histogram
Change bins=5 to bins=10 and watch the bars split. The shape of a histogram depends on the bin choice.
Matplotlib draws charts from NumPy and pandas data: line, bar, scatter and histogram, with titles and labels, saved as a PNG file. A chart answers questions that a table of numbers hides.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 6 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write the code (not run) for a bar chart of three subjects and their marks, with a title and axis labels, saved as marks.png.
Use np.histogram to count how many of [1, 2, 2, 3, 3, 3, 4] fall into 3 bins.
Say which chart you would use to show loss over 20 training epochs.
Explain it without notes
What is the difference between a figure and an axes?
Which chart would you use for a trend, a comparison, a relationship and a distribution?
What does a histogram's bin count do to the picture?
Why do the plotting examples in this topic not run in the browser, and how do you run them?
Expected output
counts: [18, 122, 243, 106, 11]
edges : [19.4, 32.2, 44.9, 57.7, 70.5, 83.2]
total : 500
19.4 | #
32.2 | ############
44.9 | ########################
57.7 | ##########
70.5 | #