Gains:
- Ability to obtain deterministic and repeatable results by printing the code that produces the graph, not the picture of the graph, to the artificial intelligence and running it itself
- Ability to validate chart output against data with value, integrity, scale and sum checksums
- Ability to impose honesty rules (from axis 0, direct label, source note) and rely on code instead of verbal guessing
You have chosen the correct chart type; Now it's time to produce it. The most reliable use of artificial intelligence here is not to ask it to "draw" the graph, but to print the code that produces the graph and run that code yourself. From where? Because the big language model is the text generator; can verbally "guess" a number, but the code processes the data as it is and produces a deterministic result (always giving the same output to the same input). In this unit, we will learn how to print graphical code (mostly Python) to AI and verify the output.
Why code, why run?
Ask a language model "what is the sales total?" If you ask, it doesn't actually collect the data; Generates a possible number. But if you print the aggregation code to it and run it, the result comes from the real data. The same goes for the chart: the code the model generates runs on your data, on your machine. The code is also repeatable: when the data is updated, you run the code again and refresh the chart.
Common tools: matplotlib and seaborn (static plot), plotly (interactive plot) with Python language; also spreadsheet programs and BI (business intelligence) tools. In this unit, we will give examples using Python/matplotlib because it is the most common; The principle is the same in every vehicle.
Tip: Instead of "give me a picture of the chart," say "give me the code that produces the chart and I'll run it." In this way, the result comes from real data and you can make as many adjustments as you want.
Step by step: from code to graphics
- Determine graphic type and message (previous unit).
- Describe the data structure to the model (column names, types; not sensitive data).
- Have the code generated, put the honesty rules in the prompt (from axis 0, tag, source note).
- Run the code yourself and look at the graph.
- Check: Is the value in the chart the same as the value in the data? Does the total/share hold?
- Improve: Change title to action title, delete unnecessary, add highlight color.
Your role: Python data visualization assistant. I have a CSV: columns "month" (YYYY-MM), "channel" (text), "revenue" (number). Write a LINE graph code with matplotlib:- Each channel is a separate line, x=month, y=come.- Let the y axis start from 0 (do not cut).- Put labels directly at the end of the lines, a separate legend is not required.- Put a placeholder for the action title in the title.- Add a small "Source: [ ... ]" note at the bottom right. Make the code complete and executable, also write the example reading line. FITTING THE NUMBER; read data from CSV.
To fix an existing chart:
Fix this matplotlib code: (1) sort the bars by value from largest to smallest, (2) make only the highest bar orange and the rest grey, (3) make the y-axis start at 0, (4) format decimals with thousands separator. Return the code in its entirety. Code: [ ... ]
For interactive chart (for dashboard):
Write an interactive line chart code using Plotly with the same data: hovering the mouse will show the month and income, and channels can be filtered. Let the axis start from 0. Give the full code.
Validation: is the chart "correct", not "pretty"?
The job is not over just because the graphics are output. Three checksums:
- Providing value: Check 2-3 random points by hand/table. Is the highest bar on the chart really the highest?
- Total/share verification: Are the shares completed to 100% in the part-whole chart?
- Visual honesty: Does the axis start at 0, is the scale linear, is it the same unit? (Details in the next unit.)
control
How to care
red flag
Value
Compare 2-3 points with data
Graph-data do not match
integrity
Are there any months/categories missing?
The gap was silently skipped
scale
Where does the Y axis start
not 0, difference is exaggerated
Total
Shares/totals
It doesn't hold 100%
Caution: The model sometimes "complets" months missing from the data or silently discards the missing row. See if the number of points on the chart matches the number of rows in the data.
three mini cases
Case 1 — Code beat prediction. An analyst first asks the model "how much is the total?" he asked, and received the answer "≈4.2 million". Then he printed out the addition code and ran it: the actual total was 3.87 million. The verbal prediction was 8% wrong. From that day on, he got every number from the code.
Case 2 — Silent missing line. One team had the monthly chart produced; everything looked fine. But March was blank in the data, and the chart skipped it and linked February to April; It looked soft because it was on trend. They noticed the number of dots (it should have been 12 instead of 11) and corrected it; There was a jump in the actual trend.
Case 3 — Reproducibility. A marketer was drawing charts by hand every month (about 40 minutes). Once he installed the code written by the artificial intelligence; In the following months it took 2 minutes to put in the new CSV and run the code. Saved 38 minutes per month and no more manual copying errors.
Weak prompt / Strong prompt
Weak:
Graph this sales data.
The model can fit a picture or give random code; the data is not actually processed, there are no honesty settings.
Strong:
Your role: Python/matplotlib helper. Data: CSV, columns "region" (text), "buyume_percentage" (number, can be negative). Write horizontal bar chart code: sort by value, highlight highest region, add y=0 reference line (display negatives), put percentage labels at bar ends. Give code executable, read from CSV, number fitting. Put an action title placeholder for the title.
The second includes data structure, honesty rules, and the "read from code, don't make it up" principle; The output is both accurate and editable.
Tool selection: when spreadsheet, when code?
You don't have to write code for every chart. For a small, one-off, simple chart, a spreadsheet (Excel, Google Spreadsheets) is often sufficient and fast. Code wins when: the data is updated regularly (refreshing the same chart every month), the chart is complex or numerous (such as small multiple charts), full control is required (integrity settings, custom labeling), or it is important that the result is repeatable. You may also ask which one is suitable for artificial intelligence.
Status
suitable vehicle
Why
One-time simple bar
spreadsheet
Fast, no code required
Report updated every month
Code (Python)
Write once, run again
Interactive/filter dashboard
Code (plotly) / BI tool
interaction required
Lots of small graphics
Code
Drawing by hand is tiring and inaccurate
Your role: data visualization consultant. I need to produce the following graph:[recipe]. [How often] is the data updated, [how many] different charts are required. Does a spreadsheet or Python code make more sense? Justify your decision; Which library do you recommend for code?
Hint: “Will I do this again every month?” If the answer to the question is "yes", the code investment almost always pays for itself. If it's a one-off, a spreadsheet will suffice.
Common mistakes
- Asking for a "picture" of the chart: When you ask for an image instead of code, the data isn't actually processed.
- Trusting the code without executing it: Putting the output on the slide without visually verifying it.
- Not providing value validation: Not comparing points on the chart to data.
- Not seeing the missing/skipped line: Not checking the number of dots.
- Treating it like a one-time job: Not keeping the code and starting from scratch every month.
In summary
Ask the artificial intelligence for the code that produces the graph, not the picture of the graph, and run that code yourself; because the code processes the data as it is and gives deterministic and repeatable results. Describe the data structure, put integrity rules (from axis 0, label, source) into the request, validate the output with value-integrity-scale-sum hashes. Code beats verbal prediction every time; But final control is yours.
Application task
For a data file of yours: (1) Describe the data structure to the AI and print a graph generation code (with honesty rules). (2) Run the code and manually compare 2-3 values in the chart with the data. (3) In the same code, sort the bars by value and add a single highlight color. (4) Save the code to use again next month.
checklist
- [ ] I wanted and ran the code that produces the chart, not the picture of it.
- [ ] The code reads the data from the real file, it does not make up numbers.
- [ ] I compared 2-3 values in the chart with the data.
- [ ] The number of points/categories is compatible with the rows in the data.
- [ ] Y axis and scale are honest; There is no axis interrupt.
- [ ] I saved the code to use again.