Plot guides
Which chart fits your data, how to read it, and the matplotlib code to make it. Or upload your file to pltchat and ask for it in plain English.
Chart types
What each plot shows, when to use it, and the matplotlib code.
- Line chartWhen to use a line chart, how to read one, and copy-paste matplotlib code to make one from your CSV or Excel data.
- Line chart with multiple seriesPlot several lines on one matplotlib chart from a long or wide table, with a legend and readable colours.
- Scatter plotHow to make a scatter plot in matplotlib, coloured by a third column, with code you can run on your own data.
- Scatter plot with a regression lineAdd a linear fit, its equation and R² to a matplotlib scatter plot using numpy.polyfit. Copy-paste code included.
- Bubble chartA bubble chart encodes a third variable as marker size. Learn when it works and get matplotlib code with a size legend.
- Bar chartWhen to use a bar chart, why the axis must start at zero, and matplotlib code to plot one from your data.
- Horizontal bar chartHorizontal bars keep long category labels readable. matplotlib barh code, sorted with the largest value on top.
- Grouped bar chartSide-by-side bars compare subgroups within each category. matplotlib code with offsets, legend and value labels.
- Stacked bar chartStacked bars show a total and its parts. matplotlib code for absolute and 100% stacked bar charts.
- Bar chart with error bars and data pointsMean bars with SD or SEM error bars and the individual replicates overlaid. matplotlib code for publication figures.
- HistogramHow to plot a histogram in matplotlib, choose the number of bins and compare two distributions.
- Density plot (KDE)A kernel density estimate shows a smooth distribution curve. Plot one in matplotlib with pandas, no seaborn needed.
- ECDF plotThe empirical cumulative distribution function compares distributions without choosing bins. matplotlib code included.
- Box plotHow to read a box plot (median, quartiles, whiskers, outliers) and make one per group in matplotlib.
- Box plot with individual pointsOverlay jittered data points on a matplotlib box plot (box plus strip plot) so readers see the raw data and sample size.
- Violin plotViolin plots show the full distribution shape per group. matplotlib code with medians and quartiles marked.
- HeatmapPlot a table of values as a colour-coded heatmap in matplotlib with imshow, a colorbar and cell annotations.
- Correlation matrix heatmapVisualise pairwise correlations between columns with a diverging colormap centred on zero. pandas + matplotlib code.
- Scatter matrix (pair plot)Plot every pair of numeric columns at once with pandas scatter_matrix: histograms on the diagonal, scatter plots off it.
- Area chartAn area chart fills the space under a line to emphasise volume over time. matplotlib fill_between code.
- Stacked area chartShow how parts of a total change over time with matplotlib stackplot. Code and tips on ordering layers.
- Pie chartWhen a pie chart is acceptable, when to use a bar chart instead, and clean matplotlib pie chart code with percentages.
- Donut chartA donut chart is a pie chart with a hole for a headline number. matplotlib code using wedgeprops width.
- Error bar plot (mean ± SD, SEM or CI)Plot means with error bars in matplotlib using errorbar. Explains SD vs SEM vs 95% confidence interval.
- Line chart with a confidence bandDraw a mean line with a shaded confidence interval or ± SD band in matplotlib using fill_between.
- Dose-response curve (IC50 / EC50)Fit a four-parameter logistic curve to dose-response data and mark the IC50, with matplotlib on a log dose axis.
- Kaplan-Meier survival curveCompute and plot Kaplan-Meier survival curves with censoring marks in plain numpy and matplotlib.
- Volcano plotPlot log2 fold change against -log10 p-value for differential expression results, highlighting significant genes in matplotlib.
- Contour plotDraw filled contours of a 2D function or gridded data in matplotlib with contourf, labelled contour lines and a colorbar.
- 3D surface plotMake a 3D surface plot in matplotlib with mplot3d, and when a contour plot or heatmap is the better choice.
- Radar chart (spider chart)Compare profiles across several metrics with a radar chart using matplotlib polar axes. Code and caveats.
- Dual-axis chart (two y-axes)Plot two series with different units on one chart using matplotlib twinx, with colour-matched axes.
- Log scale plotWhen to use a logarithmic axis and how to set log or symlog scales in matplotlib, including log-log plots.
- Time series plot with datesParse dates from a CSV and plot a time series in matplotlib with readable date ticks and highlighted periods.
- Rolling average (moving average) plotSmooth noisy daily data with a 7-day rolling mean in pandas and plot it over the raw values in matplotlib.
- Small multiples (facet grid)Split one chart into a grid of panels, one per group, with shared axes, using matplotlib subplots.
- Multi-panel figure with A, B, C labelsCombine several plots into one figure with panel letters for a paper, using matplotlib subplot_mosaic.
- Hexbin plotVisualise the density of large scatter data with hexagonal bins in matplotlib instead of overplotted points.
- Waterfall chartShow how a start value becomes an end value through positive and negative steps, with a matplotlib waterfall chart.
- Lollipop chartA lighter alternative to the bar chart for ranked values: a stem and a dot. matplotlib hlines code.
- Dumbbell chart (before and after)Compare two values per category, such as before vs after, with a dumbbell chart in matplotlib.
- Bland-Altman plotCompare two measurement methods with a Bland-Altman plot: bias and 95% limits of agreement, in matplotlib.
- Q-Q plot (normality check)Check whether data or residuals are normally distributed with a quantile-quantile plot in matplotlib, no SciPy needed.
By field
Common plots from the lab and from research data.
- Plot qPCR data (ΔΔCt fold change)Turn raw qPCR Ct values into relative expression with the ΔΔCt method and plot fold change with error bars and replicates in matplotlib.
- Plot bacterial growth curves (OD600)Plot OD600 growth curves from a plate reader export: mean ± SD per strain over time, on a log scale, in matplotlib.
- Plot XRD patternsPlot powder X-ray diffraction patterns (intensity vs 2θ) stacked with offsets, with reflections labelled, in matplotlib.
- Plot XAS spectra (XANES / EXAFS)Plot normalised X-ray absorption spectra (XANES) against energy for several samples, with an inset of the edge region, in matplotlib.
- Plot Likert scale survey dataVisualise Likert survey responses (strongly disagree to strongly agree) as a diverging stacked bar chart centred on neutral, in matplotlib.
- Plot a standard curve (calibration curve)Fit a linear standard curve (e.g. BCA or ELISA), show R², and read unknown concentrations off it, with matplotlib and numpy.
- Michaelis-Menten plot (enzyme kinetics)Plot initial reaction rate against substrate concentration, estimate Vmax and Km, and draw the Michaelis-Menten curve in matplotlib.
- Plot a 96-well plate as a heatmapLay out plate reader values as an 8×12 grid (rows A-H, columns 1-12) to spot edge effects and pipetting errors, in matplotlib.
How-to
Loading, styling and exporting figures.
- Plot a CSV file in PythonLoad a CSV with pandas and plot it with matplotlib: handle dates, pick columns, group by a category and save the figure.
- Turn an Excel chart into matplotlibRead a sheet from an .xlsx file with pandas and rebuild the Excel chart in matplotlib, so the figure is reproducible and publication-ready.
- Make a figure for a journal column widthSize a matplotlib figure for a journal's single or double column (e.g. Nature: 89 mm / 183 mm) with fonts that stay readable when printed.
- Make a colour-blind friendly plotPick colour-blind safe palettes in matplotlib (Okabe-Ito, tableau-colorblind10, viridis) and add markers so plots work in grayscale too.
- Export a plot as SVG, PDF or 300 dpi PNG/TIFFSave matplotlib figures as vector PDF/SVG/EPS or high-resolution 300-600 dpi PNG and TIFF for print, with tight bounding boxes.
- GraphPad Prism-style plot in PythonRecreate the classic Prism look in matplotlib: scatter of replicates with mean and SEM lines, bold axes, and significance brackets.