🚧 Under construction — VoTechWorks is being built. A free tech program — complimentary, as our commitment to get America working.
voTechWorksGrade 13 · a vocational technology learning center, by urbanicity
newSchoolWorks.com › VoTechWorks › Technology & Design › Data Science & Analytics › Data Visualization: Principles, Tools, and Storytelling › Lesson 3
TEC-DATA85-06 · Lesson 3 · 12 clock hours · lab

Static Visualization in Python: Matplotlib Fundamentals

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.

⚠ Pending professional review

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.

Why Static Visualization Matters

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.

The Matplotlib Object Model

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.

The Five Essential Chart Types

Line Chart

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?"

Bar Chart

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?"

Histogram

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.

Scatter Plot

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?"

Box Plot (Box-and-Whisker)

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.

Required Labels: Non-Negotiable

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.

Saving and Sharing Your 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.

Loading Data from a CSV

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.

Workplace Safety Note

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.

Peer Review and Code Quality

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.

Connecting to Credentials

Key terms8

FigureThe top-level Matplotlib object representing the entire drawing canvas; created with plt.subplots() and sized with the figsize parameter.
AxesThe plot area within a Figure that contains the actual chart, including x-axis, y-axis, title, and data elements.
tight_layout()A Matplotlib function that automatically adjusts subplot spacing so that axis labels, titles, and tick marks are not clipped at the figure boundary.
HistogramA chart that displays the frequency distribution of a single continuous variable by grouping values into bins and drawing bars proportional to count.
Box PlotA chart that summarizes a dataset's distribution using five statistics: minimum, first quartile, median, third quartile, and maximum, and flags potential outliers as individual points.
Interquartile Range (IQR)The difference between the 75th percentile (Q3) and 25th percentile (Q1) of a dataset; represented by the box in a box plot.
dpi (dots per inch)A parameter in fig.savefig() that controls the resolution of the saved image; higher values produce sharper images at larger file sizes.
ReproducibilityThe ability of a notebook or script to produce the same outputs when run from top to bottom on any compatible machine, a core quality standard in data science.
In class: Instructor live-codes a fully labeled line chart in Jupyter Notebook, narrating every method call (figure size, color parameters, tick formatting, tight_layout); students code along on their own machines. · Guided practice: students load the provided CSV (US city population data), complete a structured coding worksheet that asks them to build each of the five chart types using skeleton code with blanks to fill in. · Peer review: students exchange notebooks, run each other's code, and complete a checklist verifying that every chart has a title, labeled axes with units, and a readable font size (minimum 10pt).
Materials: Jupyter Notebook, Python 3.x, Matplotlib library, provided US city population CSV, coding worksheet, 'Python for Data Analysis' by Wes McKinney (Matplotlib appendix), CompTIA Data+ study guide (visualization domain).
Check: Submitted Jupyter Notebook with all five charts rendered and saved. Grader runs notebook top-to-bottom without errors and checks checklist criteria. Pass = all five charts render without error and all checklist items met.

Practice check8

Answer each question, then check it. Nothing is recorded; this is your own practice.

Data Visualization / CompTIA Data+
1. Which Matplotlib method call places a text label on the horizontal axis of an Axes object?
Data Visualization / CompTIA Data+
2. A data analyst wants to show how a city's population changed every ten years from 1950 to 2020. Which chart type is most appropriate?
Data Visualization / Google Data Analytics
3. After creating a chart with ax.plot(), a student calls plt.tight_layout() before plt.show(). What is the primary purpose of tight_layout()?
Data Science Workflow / IBM Data Science Professional
4. A peer reviewer runs a classmate's Jupyter Notebook using Kernel → Restart & Run All and one cell throws a NameError. What does this most likely indicate?
Data Visualization / CompTIA Data+
5. Which chart type is best suited to compare the median household income across five different US regions while also revealing the spread and outliers within each region?
Data Visualization / IBM Data Science Professional
6. In the Matplotlib object model, what is the relationship between a Figure and an Axes?
Data Visualization / Google Data Analytics
7. A student saves a chart with fig.savefig('chart.png') and then calls plt.show(). When they open the PNG file it is blank. What is the most likely cause?
Data Visualization / CompTIA Data+
8. According to standard data visualization principles, which labeling requirement must be met for an axis that displays population counts in a professional chart?
Record this lesson on my transcript. Sign in with your key and enrollment email to record lessons (enroll free if you have no key). This page stays open to read and practise.