How to Make a 3D Scatter Plot in StatFas, SPSS, R, Python and MATLAB
This tutorial draws the same 3D scatter plot, with the regression plane and the statistics behind it, in five tools. The example table has a genotype column and three numeric variables: leaf_area (X), chlorophyll (Y) and biomass (Z).
What you will make
A publication-ready 3D scatter plot with the compulsory checks and statistics that go with it, produced in five ways. The StatFas generator needs no coding and no account to run; the code versions are for readers who want a scripted workflow. For the theory behind the plot and how to read it, see the full guide.
Example data
| Column | Contents |
|---|---|
genotype | WT, MutA or MutB (optional grouping column) |
leaf_area | X variable |
chlorophyll | Y variable |
biomass | Z variable (outcome) |
Save your table as scatter3d.csv with a header row. The StatFas generator has a Load Example Data button with simulated data, so you can follow along without your own file. The example data are invented for illustration and are not real findings.
Method 1: StatFas (free, no coding)
- Open the 3D Scatter Plot Generator and click Load Example Data, or paste/upload your own file.
- Assign leaf_area, chlorophyll and biomass to X, Y and Z, and choose genotype under Colour points by group.
- Drag the figure to rotate it. Keep Regression plane (Z on X and Y) ticked to draw the fitted plane.
- Run the analysis. Read the correlations, the regression table (b, 95% CI, β, t, p, VIF) and the APA7 interpretation.
- Style the figure, then log in (free) to download it (PNG or SVG), the tables (CSV) or the Word report.
Method 2: SPSS
SPSS can draw a basic 3-D scatter plot (Graphs > Legacy Dialogs > Scatter/Dot > 3-D Scatter), but the chart cannot draw a regression plane. Run the regression separately with collinearity statistics (VIF). Syntax:
GRAPH /SCATTERPLOT(XYZ)=leaf_area WITH chlorophyll WITH biomass.
REGRESSION
/STATISTICS COEFF OUTS CI(95) R ANOVA COLLIN TOL
/DEPENDENT biomass
/METHOD=ENTER leaf_area chlorophyll.Double-click the chart in the Output Viewer to rotate it. For a plane, use R, Python or StatFas.
Method 3: R
library(scatterplot3d); library(car)
df <- read.csv("scatter3d.csv")
fit <- lm(biomass ~ leaf_area + chlorophyll, data = df)
summary(fit); confint(fit); vif(fit)
s3d <- scatterplot3d(df$leaf_area, df$chlorophyll, df$biomass, pch = 19,
angle = 45, xlab = "Leaf area", ylab = "Chlorophyll", zlab = "Biomass")
s3d$plane3d(fit) # regression plane
# interactive, rotatable version
# library(plotly); plot_ly(df, x = ~leaf_area, y = ~chlorophyll, z = ~biomass,
# color = ~genotype, type = "scatter3d", mode = "markers")Packages: install.packages(c("scatterplot3d","car","plotly")).
Method 4: Python
import pandas as pd, numpy as np, matplotlib.pyplot as plt
import statsmodels.api as sm
from statsmodels.stats.outliers_influence import variance_inflation_factor
df = pd.read_csv("scatter3d.csv") # genotype, leaf_area (X), chlorophyll (Y), biomass (Z)
X = sm.add_constant(df[["leaf_area", "chlorophyll"]]); fit = sm.OLS(df["biomass"], X).fit()
print(fit.summary())
print("VIF:", [round(variance_inflation_factor(X.values, i), 2) for i in (1, 2)])
fig = plt.figure(figsize=(6, 5)); ax = fig.add_subplot(projection="3d")
for g, d in df.groupby("genotype"):
ax.scatter(d["leaf_area"], d["chlorophyll"], d["biomass"], label=g, s=20)
gx, gy = np.meshgrid(np.linspace(df.leaf_area.min(), df.leaf_area.max(), 10), np.linspace(df.chlorophyll.min(), df.chlorophyll.max(), 10))
ax.plot_surface(gx, gy, fit.params["const"] + fit.params["leaf_area"] * gx + fit.params["chlorophyll"] * gy, alpha=0.25)
ax.set_xlabel("Leaf area"); ax.set_ylabel("Chlorophyll"); ax.set_zlabel("Biomass"); ax.legend(); ax.view_init(25, 45)
fig.tight_layout(); fig.savefig("scatter3d.png", dpi=300)Requires pandas, numpy, matplotlib and statsmodels. For an interactive plot use plotly.express.scatter_3d.
Method 5: MATLAB, OriginPro, Excel and others
MATLAB
T = readtable("scatter3d.csv");
scatter3(T.leaf_area, T.chlorophyll, T.biomass, 25, grp2idx(T.genotype), "filled");
xlabel("Leaf area"); ylabel("Chlorophyll"); zlabel("Biomass");
mdl = fitlm(T, "biomass ~ leaf_area + chlorophyll")OriginPro / Excel
OriginPro: Plot > 3D > 3D Scatter. Excel has no native 3D scatter chart; use another tool or StatFas.
Which method should you choose?
| Tool | Cost and skill | Plot | Statistical checks | Report-ready output |
|---|---|---|---|---|
| StatFas | Free, in the browser | Rotatable, regression plane | Correlations, regression, VIF | Yes, to Word |
| SPSS | Licence needed | Basic 3-D scatter | Regression with VIF | Tables only |
| R | Free, coding | Yes (scatterplot3d, plotly) | lm, car::vif | Manual |
| Python | Free, coding | Yes (matplotlib, plotly) | statsmodels | Manual |
Choose StatFas for speed and APA7-ready output, SPSS if your department already licenses it and you only need the statistics, and R or Python when the analysis must be scripted and reproduced in a pipeline.
How to report the result in APA7
Report the model (R², F, df, p) and, for each predictor, b with its 95% CI, β, t and p, plus VIF if you checked multicollinearity. Say in the figure note that the plot is a 3D projection and give the viewing angle. StatFas writes this paragraph and the regression table for you.
See the guide for an example paragraph.
Troubleshooting
- The plane looks tilted the wrong way. Check which variable is on which axis; the plane predicts Z from X and Y.
- VIF is very high. X and Y overlap. Drop one, combine them, or interpret the coefficients cautiously.
- Points are hard to see. Reduce the marker size, rotate the plot, or colour by group.
- Need a fixed angle for a paper. Rotate to the angle you want, then download that view.
Frequently asked questions
Can SPSS draw a regression plane?
No. SPSS can draw the 3-D scatter and run the regression, but the plane has to be drawn in another program.
Which tool gives a rotatable plot for free?
StatFas, plotly in R or Python, and MATLAB all give rotatable 3D scatter plots.
Related tools, guides and tutorials
- Guide: 3D Scatter Plot Explained: How to Make, Rotate and Report It
- Multiple linear regression calculator
- Regression calculator
- Regression tutorial
- Correlation calculator
- Pearson correlation calculator
- Pearson correlation explained
- Canonical correlation analysis
- Correlation tutorial
- PCA Biplot Generator
- Parallel Coordinates Plot Generator
- Ternary Plot Generator
- All tutorials
- All blog posts
References
- American Psychological Association. (2020). Publication manual of the American Psychological Association (7th ed.).
- O’Brien, R. M. (2007). A caution regarding rules of thumb for variance inflation factors. Quality & Quantity, 41(5), 673–690.
- Cohen, J., Cohen, P., West, S. G., & Aiken, L. S. (2003). Applied multiple regression/correlation analysis for the behavioral sciences (3rd ed.). Lawrence Erlbaum Associates.