Mismatched lengths
plt.plot(days, marks)The x and y sequences must have compatible lengths.
Line, bar, histogram and pie charts
Unit 5 · Visualize data with Matplotlib
Matplotlib is a Python plotting library. Choose a chart, adjust the sample values, and inspect the matching Python code. The preview beside the editor is a browser-rendered teaching companion; the editable Python example runs Matplotlib inside Pyodide in your browser. The starter code saves its figure to the virtual file system so Matplotlib does not place a separate display below the lesson.
Use comparable positive values for this starter dataset. The preview responds to your edits.
Python code for this chart
import matplotlib.pyplot as plt
days = ["Mon","Tue","Wed","Thu","Fri"]
visitors = [12,18,15,22,17]
plt.plot(days, visitors, marker="o")
plt.title("Daily visitors")
plt.xlabel("Day")
plt.ylabel("Visitors")
plt.grid(True)
plt.savefig("chart.png")
print("Chart saved to chart.png")Output
Your program's output will appear here.
NameError: name 'mark' is not defined
NameError: A name was used before Python could find a variable or function with that name.
IndexError: list index out of range
IndexError: The requested position is outside the items in this list or sequence.
KeyError: 'email'
KeyError: That key does not exist in this dictionary.
TypeError: can only concatenate str (not "int") to str
TypeError: This operation does not work with the kind of value it received.
ZeroDivisionError: division by zero
ZeroDivisionError: A number cannot be divided by zero.
SyntaxError: invalid syntax
SyntaxError: Python could not understand the structure of this line. Check spelling, brackets, colons, and quotes.
IndentationError: expected an indented block
IndentationError: The spaces at the start of a line do not match Python's block structure.
import matplotlib.pyplot as plt gives pyplot a short alias, plt.
Pass sequences of labels and numeric values.
A title and axis labels explain what the marks mean.
plt.savefig() writes a PNG to the browser's virtual file system.
For a histogram, the bars count values in bins; for a bar chart, each category has a bar. Use a histogram for a numeric distribution and a bar chart for category comparisons.
plt.plot(days, marks)The x and y sequences must have compatible lengths.
Histogram for named categoriesHistograms show numeric distributions; use bars for named categories.
A chart without title or axesAdd a concise title and axis labels so readers know what is measured.
First run in a fresh Pyodide sessionThe runtime fetches the package when first imported; allow it to finish loading.
1. Which chart shows the distribution of numeric marks?
2. What does plt.xlabel() do?
3. Why use plt.grid(True)?