03 · What You Need to Know
How Generative AI Can Help Produce Scientific Figures
What Can AI Actually Do When Writing Visualization Code?
Generative AI can translate a natural-language description of a figure into source code for an established plotting library.
For example, a researcher might request a scatterplot showing the relationship between student engagement and assessment performance, with separate markers for two instructional groups.
AI may generate code that selects the relevant columns, creates the plot, assigns visual encodings, adds labels, and saves the output.
It can also help modify existing figures by changing axis formatting, reorganizing legends, adding reference lines, or arranging multiple panels.
More demanding tasks include plotting confidence intervals, displaying model coefficients, or creating visualizations from repeated-measures data. These are feasible coding tasks, but they require precise analytical instructions.
The model's ability to produce plotting syntax should not be confused with its ability to determine which scientific representation is appropriate.
Which Scientific Visualization Libraries Can AI Help With?
AI can generate code for several widely used scientific visualization systems. The appropriate library depends on the programming environment, project requirements, and desired output.
| Library or tool |
Typical research use |
What researchers should verify |
| matplotlib (Python) |
General-purpose scientific figures, customized axes, and multi-panel layouts |
Data mappings, coordinate transformations, limits, and plotting commands |
| seaborn (Python) |
Statistical visualizations, distributions, and grouped comparisons |
Default estimators, aggregation, uncertainty displays, and categorical ordering |
| ggplot2 (R) |
Layered statistical graphics and publication figures |
Statistical transformations, aesthetic mappings, grouping, and scales |
| Plotly |
Interactive plots and exploratory dashboards |
Data aggregation, interactive filtering, exported outputs, and accessibility |
| Specialized scientific libraries |
Domain-specific figures such as maps, networks, or multidimensional displays |
Disciplinary conventions, coordinate systems, units, and domain-specific assumptions |
Researchers should prefer tools appropriate to their established analytical workflow rather than changing software environments solely because AI produces more familiar code for another library.
Why Does the Prompt Need to Specify the Analytical Meaning of the Figure?
A request such as "create a graph comparing the groups" leaves several scientific decisions unresolved.
Should the figure show individual observations, means, medians, estimated marginal means, or model-adjusted differences? Are the groups independent? Should uncertainty intervals be included?
AI may select defaults that produce a plausible chart but do not match the researcher's analytical objective.
A more informative request specifies the data structure, variable meanings, grouping rules, intended statistical quantities, and required graphical elements.
For example, asking for a plot of already calculated regression coefficients with their corresponding 95% confidence intervals is different from asking AI to estimate a regression model and create the figure. The latter delegates additional analytical decisions.
Researchers should establish the appropriate visualization for the research question before treating the plotting implementation as a routine coding task.
Why Can Correctly Executed Plotting Code Produce Incorrect Figures?
Programming libraries generally determine whether plotting instructions can be executed, not whether the resulting representation is scientifically appropriate.
A plotting function may accept an incorrect variable, an unintended aggregation, or an inappropriate axis scale without reporting an error.
For instance, a script may calculate group means after silently excluding missing observations. The figure renders normally, but its effective sample sizes differ from those used in the reported analysis.
Similarly, code may connect observations from unrelated participants with lines, creating the appearance of individual trajectories that were never measured.
These are analytical errors expressed graphically. They may be difficult to identify through visual inspection alone.
How Can AI Misinterpret Variable Names and Data Types?
Research datasets frequently use abbreviated names, numerical category codes, and variables whose meanings are not obvious from their labels.
A column named group might identify an instructional condition, a sampling cluster, or a participant category. A numerical variable coded as 1, 2, and 3 may represent unordered categories rather than a continuous quantity.
If AI treats category codes as numerical measurements, it may recommend inappropriate axis spacing, smoothing, or statistical summaries.
Researchers should provide a data dictionary or explicit descriptions of relevant variables when requesting plotting code.
The resulting script should be inspected to confirm that categorical, ordinal, continuous, and temporal variables are handled according to their actual meanings.
Why Should Statistical Summaries Be Calculated Carefully?
Some plotting libraries automatically calculate statistical summaries. For example, a plotting function may estimate a group mean or display an uncertainty interval without requiring the researcher to calculate those values separately.
These conveniences can introduce ambiguity when the default calculation differs from the intended analysis.
A researcher may intend to display medians while the plotting function calculates means. Another figure may show a confidence interval based on a resampling procedure that differs from the method used in the manuscript.
AI-generated code can also confuse standard deviations, standard errors, confidence intervals, and prediction intervals.
Researchers should identify the statistical quantity represented by every plotted summary and verify its calculation.
When figures communicate primary inferential results, plotting verified estimates from the statistical analysis may reduce the risk of inadvertently performing a different calculation during visualization.
How Should Researchers Handle Missing Data in AI-Generated Plots?
Missing-data handling can change the observations represented in a figure.
Some plotting functions automatically omit observations with missing values in variables required by the plot. This may be appropriate, but it can create discrepancies between the visualized sample and the sample used in another analysis.
Researchers should determine whether the plotted observations correspond to the intended analytical dataset.
For grouped figures, they should also check whether missing values affect groups differently.
AI-generated plotting code should not silently introduce imputation, exclusion, or substitution procedures that were not specified in the research methodology.
When sample sizes differ across figures or analyses, the distinction should be explained where it affects interpretation.
Can AI Generate Confidence Intervals and Error Bars Correctly?
AI can write code that calculates or plots uncertainty intervals, but the correctness of those intervals depends on the underlying statistical procedure.
For example, a 95% confidence interval for a regression coefficient is not necessarily calculated in the same way as a confidence interval for a group mean.
Clustered observations, repeated measurements, survey weights, and model-specific assumptions may require specialized estimation procedures.
AI may produce a conventional formula without recognizing these requirements.
Researchers should therefore verify whether the code calculates the intended uncertainty measure and whether it corresponds to the statistical model used in the study.
Where possible, figures should use estimates and intervals produced by the verified analysis rather than independently recalculating them through an unrelated plotting procedure.
How Can AI Introduce Misleading Axes or Scales?
AI-generated plotting code may choose axis limits automatically or introduce custom limits to improve visual appearance.
These decisions can affect interpretation.
For example, truncating the vertical axis of a bar chart can exaggerate small differences because bar length encodes magnitude. In contrast, a nonzero baseline may be appropriate for some line plots or scatterplots when the scale is clearly communicated.
Logarithmic transformations can help represent values spanning several orders of magnitude, but they require appropriate treatment of zero and negative values.
Researchers should inspect all axis limits, transformations, tick labels, and units rather than assume that the plotting library selected a scientifically appropriate scale.
AI may help identify potentially misleading graph axes and scales, but such assessments must consider the actual visual encoding and research context.
Can AI Generate Multi-Panel Scientific Figures?
Yes. AI can write code that combines several plots into a coordinated figure, including shared axes, aligned panels, and consistent legends.
Multi-panel figures are common when researchers need to present related analyses or compare outcomes across conditions.
However, layout consistency should not conceal important differences between panels.
For example, using different axis ranges across panels may make comparisons difficult, while forcing identical ranges may obscure meaningful variation in particular datasets.
Researchers should determine whether shared scales are scientifically appropriate and verify that panel labels, sample sizes, and statistical summaries correspond to the correct analyses.
How Can AI Help Make Figures Accessible?
AI can assist with readable labels, colorblind-conscious palettes, marker shapes, line patterns, and alternative text.
However, accessibility involves more than choosing attractive colors.
Figures should remain interpretable when color distinctions are unavailable, labels should identify meaningful quantities, and legends should not require readers to infer information from appearance alone.
For complex scientific figures, accessible descriptions should communicate the figure's structure and relevant findings without introducing unsupported interpretations.
AI assistance with accessible research figure descriptions can be useful, but the final descriptions should be checked against the actual visual and underlying evidence.
Can AI-Generated Visualization Code Be Reproducible?
Yes, provided the code and its computational requirements are preserved.
Researchers should archive the plotting script, relevant data or authorized access arrangements, package versions, execution instructions, and any configuration settings required to recreate the figure.
Random sampling, jitter, and other stochastic graphical operations may require recorded random seeds when exact placement or output consistency matters.
Researchers should also distinguish between reproducibility of the plotted data and pixel-identical reproduction of the rendered image. Font availability, rendering backends, and software versions may affect appearance without necessarily changing the underlying values.
The plotting code should be maintained as part of the reproducible research code workflow.
What Should Researchers Verify Before Publishing an AI-Generated Figure?
Verification should connect the plotted figure to the data and analysis from which it was derived.
Researchers should check variable mappings, data transformations, group definitions, statistical estimates, uncertainty intervals, scales, labels, and sample sizes.
For important figures, it may be useful to compare the numerical values represented in the plot with verified tables or independent calculations.
A figure should not be accepted merely because its appearance matches the researcher's expectations.
When AI modifies an existing visualization, checking the modified figure against the underlying data is especially important because seemingly cosmetic changes may alter scientific meaning.