Data Visualization

Critiquing AI-Suggested Visualizations


Learning Objectives

  • You can check whether an AI-suggested chart matches the question.
  • You can check whether AI-generated plotting code uses the real DataFrame columns.
  • You can identify misleading or unsupported chart choices.
  • You can write a precise visualization prompt that keeps you in control.

This chapter develops the next AI-collaboration skill: critiquing AI-suggested visualizations. The previous skill was working with libraries you are still learning.

The risk is slightly different now. With pandas, the AI might invent a method name or use the wrong column. With charts, the code might be valid and the image might look polished, while the chart still answers the wrong question or suggests a misleading conclusion.

Your job is to critique the chart idea, not only the syntax.

Four Checks

When an AI assistant suggests a chart, check four things.

First, does the chart match the question?

If the question is “How has study time changed over days?”, a subject-total bar chart does not answer it.

Second, does the code use the real columns?

Your study-log DataFrame has:

subject, minutes, date

Code that uses "topic", "duration", or "day" is written for a different table unless you adapt it.

Third, did the code prepare the right summary?

For total minutes by subject, the code should group by subject and sum minutes:

summary = df.groupby("subject", as_index=False)["minutes"].sum()

Plotting raw session rows may answer a different question.

Fourth, can you explain the result honestly?

A chart can show that one subject has more logged minutes than another. It cannot prove that one subject is more important, harder, or better. Those are interpretations beyond the chart.

What a chart can show

0 / 5 points

Which statement best matches the role of visualizations in this part?

Critique an AI-suggested chart

0 / 10 points

An AI assistant is asked:

How has my study time changed over days?

It suggests:

sns.barplot(data=df, x="subject", y="minutes")

Your study-log DataFrame has columns subject, minutes, and date.

In a short paragraph, about 4-6 sentences, critique the suggestion. Explain what is useful or plausible about it, what does not match the question, and what summary/chart would better answer the question. Explicitly describe preparing one total per date and putting those dates in chronological order. The sentence range is guidance, not a strict limit.

A Worked Critique

Suppose you ask:

How has my study time changed over days?

Use this complete six-row sample so the suggestion and the resulting image can be checked against the same data:

import pandas as pd
records = [
{"subject": "math", "minutes": 45, "date": "2026-05-10"},
{"subject": "history", "minutes": 30, "date": "2026-05-11"},
{"subject": "programming", "minutes": 60, "date": "2026-05-11"},
{"subject": "math", "minutes": 25, "date": "2026-05-12"},
{"subject": "programming", "minutes": 90, "date": "2026-05-13"},
{"subject": "history", "minutes": 50, "date": "2026-05-13"},
]
df = pd.DataFrame(records, columns=["subject", "minutes", "date"])

An assistant suggests:

import seaborn as sns
sns.barplot(data=df, x="subject", y="minutes")

This code may run. It uses real columns. But it does not answer the question. It compares subjects, not days.

Here is what the suggestion actually draws for a small sample log:

Fig 1. -- A seaborn bar chart with bars for math, history, and programming and a thin vertical uncertainty interval on each bar; the axes are labeled only with the raw column names "subject" and "minutes", and there is no title.

There is another issue, and the picture shows it. sns.barplot groups the raw rows by the category on the x-axis. By default, each bar is the mean of the minutes values for that subject, and seaborn adds uncertainty intervals. Those bars are not subject totals and they do not show change over time. For a beginner project, it is clearer to prepare the daily total yourself:

daily = df.copy()
daily["date"] = pd.to_datetime(daily["date"])
daily = daily.groupby("date", as_index=False)["minutes"].sum()
daily = daily.sort_values("date")

Then plot and label the corrected chart:

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
sns.lineplot(data=daily, x="date", y="minutes", marker="o", ax=ax)
ax.set_title("Study minutes over time")
ax.set_xlabel("Date")
ax.set_ylabel("Minutes")
plt.show()

Now the chart matches the question: one total per day, in date order.

Fig 2. -- A line chart titled "Study minutes over time" showing daily totals of 45, 90, 25, and 140 minutes in chronological order.

Rebuild that fix yourself: arrange the preparation and plotting lines that answer the daily-minutes question.

The right chart for the question

0 / 5 points

The question is: “How many total study minutes were logged on each date?” Arrange the blocks to prepare the daily totals and draw a chart that answers it. Assume df already exists with columns subject, minutes, and date.

The imports and related preparation lines are grouped. Arrange the remaining stages according to their data dependencies.

Better Prompts for Chart Help

A vague prompt:

Make a cool chart for my study log.

This invites the assistant to guess the question, the data shape, and the chart type.

A better prompt:

I have a pandas DataFrame named df with columns subject,
minutes, and date. The date column can be converted with
pd.to_datetime. I want one chart that answers this question:
how many total study minutes were logged on each date?
Please prepare the daily totals first, sort by date, then
make a simple line chart with matplotlib or seaborn. Use
readable intermediate variables and return fig, ax instead
of calling plt.show().

This prompt gives the assistant less room to drift:

  • it names the DataFrame columns,
  • it names the question,
  • it names the summary step,
  • it asks for date sorting,
  • and it preserves the project boundary by returning fig, ax.

Prompt a daily study chart

0 / 10 points

Write a prompt that asks a large language model to create Python code only.

The generated code must define a function named make_daily_minutes_chart(df) with this exact behavior:

  • df is a pandas DataFrame with columns subject, minutes, and date,
  • leave the input DataFrame unchanged (working on a copy is one way),
  • convert the date column with pd.to_datetime,
  • group rows by date and sum minutes,
  • put the daily totals in chronological order,
  • create a simple line chart of daily minutes,
  • set the title to "Study minutes over time",
  • set the x-axis label to "Date" and the y-axis label to "Minutes",
  • return (fig, ax),
  • do not call input(...),
  • do not print anything,
  • and do not call plt.show() inside the function.

Ask for readable intermediate variables rather than one dense method chain. Ask for Python code only.

Where You Are in the Arc

The course’s AI-collaboration arc now includes:

Course sectionAI skillWhat it gives you
Getting Started with ProgrammingReading code you didn’t writeKnowing what a piece of code does
Making Decisions and Repeating WorkVerifying behavior and finding edge casesKnowing whether what it does is right
Organizing Code with FunctionsSpecifying what you wantKnowing what to ask for in the first place
Reading and Writing FilesDetecting plausible-but-wrong codeKnowing when “it runs” is not “it works”
Summarizing Your DataComparing approachesKnowing how to choose between several right answers
Structuring Your DataCritiquing data designsKnowing whether the data is in the right shape
Using LibrariesWorking with AI on libraries you’re learningKnowing how to verify unfamiliar library code
Data VisualizationCritiquing AI-suggested visualizationsKnowing whether a chart serves the data and question
Games and Programming in the WildIterating with AI on a real projectKnowing how to use AI without losing control of the finished work

The next chapter applies the skill directly. You will add charts to the study log, but you will keep the same boundaries you have built over the course: load data, create the DataFrame, prepare summaries, plot, and check the result.

Check Your Understanding

  1. What four checks should an AI-suggested chart pass?
  2. Why can chart code be valid and the image polished while the chart is still the wrong chart?
  3. The question is about change over days, but the suggestion is sns.barplot(data=df, x="subject", y="minutes"). What is wrong, and what should the code do instead?
  4. What should a good visualization prompt include?

AI Study Aid

Create a chapter diagram

We're looking into to what extent AI-generated diagrams could help with studying.

Use this study aid to generate an AI-generated visual summary of the material you just studied. Each diagram style emphasizes the content in a different way, so you can choose the focus that feels most useful.

Using the diagram generator is voluntary and does not affect your course progress. We encourage you to try it out and see if it helps, but it's totally up to you! Your answers help us understand how to make better study aids in the future.

Diagrams tried: 0