Gains:
- Ability to visualize functions, intersections and data by printing Matplotlib code to artificial intelligence and running the code, and to choose the appropriate graph type for the purpose
- Ability to check whether a graph reflects mathematics correctly by comparing it with known properties of the function, axis range, asymptotes and at least one point calculation.
- Ability to visually locate roots and intersections by using visualization as a verification tool and provide accurate starting points for numerical methods
A graph tells more than a thousand equations. Visually seeing how a function behaves, where its roots are, where two curves intersect, or how data is distributed is one of the most powerful ways to understand and verify mathematics. Mathematical visualization is the visual representation of mathematical objects (functions, data, geometric shapes) with graphics. The standard tool for this in Python is the Matplotlib library. In this unit you will learn how to use AI as an assistant that generates visualization code and, more importantly, how to check that the graph reflects the mathematics correctly.
Visualization is also a verification tool. We saw in the previous unit: graphing the root of an equation before finding it numerically shows roughly where the root is and gives an accurate starting estimate. Seeing the graph of the function before an integral calculation allows you to understand whether the sign of the result (positive/negative area) makes sense. The graph asks "does this result make sense?" It is the visual answer to the question.
Major uses of visualization in mathematics
- Function behavior: Increasing/decreasing regions, maximums/minimums, asymptotes of an f(x).
- Finding roots and intersections: The places where the curve intersects the x-axis (roots), the intersection of two curves.
- Area/integral intuition: Visual representation of the area under the curve.
- Data distribution: Histogram, scatter plot, box plot.
- Geometry: Triangles, circles, transformations.
- Course material: Explaining a concept visually to students.
Step by step: Producing accurate graphics with AI
1. Be clear about what you want to show. "Draw sin(x)" is not enough; "Plot sin(x) in the range [−2π, 2π], with axes labeled and grid" is better.
2. Write Matplotlib code to the AI. Ask for the code, not the output image; You run the code and see the graph.
3. Compare the graph to the math. Does the graph show known properties of the function? sin(x) must oscillate between −1 and 1; a parabola must be symmetric; an exponential function must increase rapidly. If the chart does not show these, there is an error in the code.
4. Check the axis range. Incorrect spacing may hide an important root or behavior. Make sure it covers the interesting region of the function.
5. Check label and scale. Are the axes labeled? Is the scale (linear/log) correct? A misleading scale gives the wrong impression.
6. Confirm with a numerical dot. If the graph shows f(2)≈3, verify this by calculation. The graph may lie (if the wrong function is drawn).
Tip: After drawing a graph, verify it by independently calculating at least one point on it. If the graph shows y=1 at x=0, calculate f(0) manually. If they match, the correct function has probably been drawn; If it does not match, the AI may have encoded a wrong expression.
Resolution and sampling: where the graph lies
A Matplotlib plot is not actually a continuous curve; It calculates the function at a finite number of points and connects these points with straight lines. The number of these points is called sampling resolution. If the resolution is low (e.g. only 10 points generated with linspace in NumPy), a fast oscillating function (e.g. sin(50x)) may look completely wrong in the graph — most of the peaks and troughs fall between the two sampling points and disappear. This is called aliasing in signal processing. AI sometimes writes code that produces a small number of points; The result is a fluid but misleading graph.
The antidote is simple: keep the number of sampling points high in fast-changing functions (e.g. np.linspace(a, b, 1000)). Also, if a graph has an angular, toothed, or irregular appearance that you don't expect, this is often a side effect of the low resolution and not the actual behavior of the function; Increase the number of points and check if the graph changes. If the graph changes significantly with the number of points, you are not yet seeing the true shape of the function.
Caution: A low-resolution graph may completely misrepresent a fast-oscillating function — or even fit a pattern that does not exist. When drawing a critical graph, deliberately choose a high number of sampling points and verify that the graph remains stable as you increase the number of points.
Chart type selection
Purpose
suitable graphic
Matplotlib function
Function curve
line chart
plot()
data points
Scatter plot
scatter()
distribution
histogram
hist()
Two variable relationship
Scatter + curve
plot() + scatter()
Categorical comparison
bar chart
bar()
Surface/3D
3D surface
plot_surface()
three mini cases
Case 1 — Hidden root. One student had a graph plotted to see the roots of a polynomial, but chose the YZ axis range [−1, 1]; whereas the roots were around x=3 and were not visible on the graph at all. The student asks "doesn't this function have a root?" He was surprised, then when he changed the spacing to [−5, 5], the roots appeared. Lesson: wrong spacing hides the math.
Case 2 — Incorrect function. A teacher wanted to make the AI draw "cos(x²)", but the code mistakenly wrote "cos(x)²" (i.e. cos²(x)). The two functions are very different. When the teacher compared the graph with the expected value at x=√π, he saw that it did not match and caught the error. The place of parentheses changes everything.
Case 3 — Visual verification took root. An engineer first graphed the function and saw that it intersected the x-axis in two places (~1.2 and ~4.7). With this visual information, it gave the digital root finder accurate initial guesses and found both roots precisely. Without the graph, it could only converge to a root. Two roots in 5 minutes.
Four copyable templates
1) Function chart:
Write a Matplotlib code that plots the function [f(x)] in the range [a, b]. Create an x array with NumPy, label the axis, add a grid, put a title. I will run the code; identifying the image. Choose the appropriate spacing so that the roots/special points are visible.
2) Intersection of two curves:
Draw [f(x)] and [g(x)] functions in the range [a, b] on the same graph. Show them in different colors, add a legend. Adjust the axis spacing so I can see roughly where the intersection points are.
3) Visual + numerical verification:
Plot [f(x)] AND print the actual f values of the 3 sample points (x=[values]) on the graph. So I can compare the chart with the numerical values. Just give the code.
4) Data histogram:
Write code that plots a histogram of the following list of data: [data]. Select appropriate number of ranges (bins), label the axes. Also print the mean and standard deviation. I will run the code.
Weak prompt / Strong prompt
Weak: "Plot the function 1/(x−2)."
Result: The code may not properly handle the vertical asymptote at x=2; The graph shows a misleading vertical line at x=2 and the behavior of the function is misunderstood.
Strong: "Plot the function 1/(x−2) on the range [−5, 5], but show the vertical asymptote at x=2 correctly: limit values near the asymptote or plot them as two separate parts. Label the axes, mark the asymptote with a dashed line."
Result: The asymptote is displayed correctly, the graph reflects the real behavior of the function.
Common mistakes
- Wrong axis range. The range that does not cover the interesting region of the function (roots, vertices) obscures the mathematics.
- Ignoring asymptotes. Vertical asymptotes in functions like 1/x lead to misleading lines; special handling required.
- Parentheses/notation error. Differences such as cos(x²) and cos²(x) are passed into the code incorrectly; The graph shows another function.
- Unlabeled axes. What is drawn remains unclear; It is a serious deficiency in the course material.
- Not confirming the chart numerically. If the graph plots the wrong function, only point calculus will catch it.
- Misleading scale. The logarithmic/linear scale confusion gives the wrong impression.
Caution: Just because a chart "looks pretty" does not make it right. AI may produce a graph that is aesthetically pleasing but mathematically incorrect—for example, it may draw the wrong function, in the wrong range, or with a distorted asymptote. Always compare the graph with known properties of the function it plots and with at least one point calculation.
In summary
Visualization is both an expression and a verification tool: visually seeing the behavior of a function, its roots and intersections, is a powerful way to catch errors and find accurate numerical starting points. The AI quickly generates Matplotlib code; You run the code, compare the graph to known properties of the function, check the axis range and asymptotes, and confirm at least one point numerically. A beautiful graph is not a correct graph; always compare with math.
Application task
Choose an interesting function (e.g. 1/(x−2), which has a vertical asymptote, or a polynomial with several roots). Have the AI draw the graph with the 1st and 3rd templates and print the real values of a few points. Run the code and see the graph. Compare the features on the graph (roots, asymptote, vertices) to the known mathematics of the function. Verify at least one point manually or with SymPy. Change the axis range and see if any hidden behavior emerges.
checklist
- [ ] I clearly stated what I wanted to draw with spacing and labels.
- [ ] I ran the code and actually saw the graph.
- [ ] I compared the graph with known properties of the function.
- I verified that the [ ] axis range covers the interesting region.
- [ ] I checked that the asymptote/undefined points are shown correctly.
- [ ] I have confirmed at least one point numerically.