Objective. Students will produce five distinct chart types (line, bar, histogram, scatter, box) in Matplotlib with proper titles, axis labels, and legend using a provided real-world dataset.
This lesson, its worked examples and its practice questions has not yet been verified by an industry-certified professional or by a certification or approval body. It is a study draft and may contain errors. Do not use it as instructions for work on a job site or on live equipment. Always follow your instructor, your supervising professional, and current official references and regulations.
VoTechWorks program approval and accreditation are still in progress. Credentials are issued only by the certifying bodies named in each program, after their own exams.
Before a chart reaches an interactive dashboard, it usually starts as a static image. Static visualizations are reproducible, easy to embed in reports and slide decks, and fast to render on any machine. Matplotlib is the foundational plotting library in Python. Nearly every other Python visualization tool—Seaborn, Pandas plot, and others—builds on top of it. Mastering Matplotlib gives you precise control over every visual element and prepares you to work with higher-level libraries more confidently.
CompTIA Data+ and the Google Data Analytics Certificate both test your ability to select the right chart type for the data at hand, label it correctly, and communicate findings clearly. The skills in this lesson map directly to those exam domains.
Matplotlib organizes a chart into two main objects:
The most common way to create both at once is:
```python
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(8, 5))
```
Always use `fig, ax = plt.subplots()` rather than the older `plt.plot()` shortcut when building anything you intend to submit or share. The object-based approach keeps your code explicit and readable.
Use a line chart when data points are connected over an ordered dimension, most often time. Call `ax.plot(x, y)`. Line charts answer questions such as "How did population change over decades?"
Use a bar chart to compare discrete categories. Call `ax.bar(categories, values)` for vertical bars or `ax.barh()` for horizontal. Bar charts answer "Which city has the largest population?"
Use a histogram to show the distribution of a single continuous variable. Call `ax.hist(data, bins=20)`. Choose a bin count that reveals the shape without hiding detail or creating noise.
Use a scatter plot to explore the relationship between two continuous variables. Call `ax.scatter(x, y)`. Scatter plots answer "Is there a pattern between city area and population?"
Use a box plot to summarize a distribution and highlight outliers. Call `ax.boxplot(data)`. The box spans the interquartile range (IQR); the line inside is the median; whiskers extend to the data range or a defined multiple of the IQR.
A chart without proper labels is incomplete and can mislead the reader. Every chart you submit must have:
1. Title — `ax.set_title('Your Title', fontsize=14)`
2. X-axis label with units — `ax.set_xlabel('Year', fontsize=12)`
3. Y-axis label with units — `ax.set_ylabel('Population (millions)', fontsize=12)`
4. Legend (when more than one data series is plotted) — add `label='Series Name'` inside each plot call, then call `ax.legend()`
5. Readable font size — minimum 10pt for any visible text
After adding all elements, call `plt.tight_layout()` to prevent labels from being cut off at the edge of the figure.
To save a figure to disk, call `fig.savefig('chart_name.png', dpi=150)` before `plt.show()`. The `dpi` parameter sets image resolution; 150 is sufficient for most reports. Saving before showing prevents a blank file on some systems.
You will use Pandas to load the provided US city population CSV, then pass column values directly to Matplotlib:
```python
import pandas as pd
df = pd.read_csv('us_city_population.csv')
```
Access columns as `df['column_name']` and pass them to your chart calls. Always inspect the first few rows with `df.head()` and check data types with `df.dtypes` before plotting so you know what you are working with.
Data science work is office and computer-based. The primary ergonomic risks are repetitive strain injury and eye fatigue from extended screen time. Follow your institution's ergonomic guidelines: keep your display at arm's length, take short breaks every hour, and position your keyboard so your wrists remain neutral. If you use shared lab machines, do not store credentials or personal data on the local file system; save work to your assigned cloud or network folder.
During peer review, run your partner's notebook from the top using Kernel → Restart & Run All. This confirms that every cell executes in order without errors—a basic form of reproducibility testing used in real data teams. Use the checklist to verify titles, labeled axes, units, and font size on every chart. Giving specific written feedback ("The y-axis is missing units") is more useful than a simple pass/fail note.
Answer each question, then check it. Nothing is recorded; this is your own practice.
A free tech program — complimentary, as our commitment to get America working. Help us build VoTechWorks. Tell us what works, what doesn’t, and what you want to learn.