Skip to content

MatplotlibThemes

H.P. Gansevoort edited this page Nov 27, 2026 · 10 revisions

Matplotlib Themes

These themes give a chart the matplotlib look in pure .NET, with no other changes needed. No Python runtime is required.

The two themes mimic matplotlib's visual style: the pre-2.0 classic look and the modern v2.0+ default. MatPlotLibNet renders both entirely on its own.


Theme.MatplotlibClassic — the pre-2.0 look

This theme uses a white background, the bgrcmyk 7-color cycle, DejaVu Sans at 12pt, and a grid that is hidden by default. The grid is hidden because matplotlib ships with plt.grid(False); users turn it on themselves.

using MatPlotLibNet;
using MatPlotLibNet.Styling;

double[] x = [0, 1, 2, 3, 4, 5];
double[] y1 = [0, 1, 4, 9, 16, 25];
double[] y2 = [0, 2, 4, 6,  8, 10];

Plt.Create()
    .WithTheme(Theme.MatplotlibClassic)
    .WithTitle("Classic matplotlib look")
    .AddSubPlot(1, 1, 1, ax => ax
        .Plot(x, y1, s => s.Label = "Quadratic")
        .Plot(x, y2, s => s.Label = "Linear")
        .WithLegend())
    .Save("classic.svg");

Color cycle — bgrcmyk

# Hex Name
0 #0000FF blue
1 #008000 green
2 #FF0000 red
3 #00BFBF cyan
4 #BF00BF magenta
5 #BFBF00 yellow
6 #000000 black

At a glance

Property Value
Background #BFBFBF (matplotlib's figure.facecolor: 0.75)
Axes background #FFFFFF (white)
Foreground text #000000 (pure black)
Font family DejaVu Sans, Bitstream Vera Sans, sans-serif
Font size 12.0pt
Grid hidden by default (Visible = false)
Grid when shown black, dotted, 0.5 pt (0.69 px)
Minor grid the grid when shown, in its own stroke, on an axis whose minor ticks are on (a log or logit axis unless they are switched off)
Minor ticks off until switched on; a log or logit axis draws its own (2 to 9 times each power on a log axis) unless they are switched off; a linear step split in four, in five when it is 1, 2.5 or 5 times a power of ten (xtick.minor.ndivs: auto)
Grid's place over every series, patch and span (axes.axisbelow: False, the axis at zorder 2.5)
Spines 1 pt (1.39 px)
Lines 1 pt (1.39 px) when the series is given no width
Dashes dashed 6 pt on and 6 pt off, dotted 1 and 3, dash-dot 3, 5, 1 and 5 (lines.dashed_pattern and the others), the same at any width (lines.scale_dashes: False), in the SVG and in the PNG
Line corners round (lines.solid_joinstyle) for every line, contour and streamplot lines included, and for the edge of what matplotlib draws as a collection (a scatter marker, a filled band, a violin, a hexbin, a 3-D face, a barb); a bar, a wedge and a box keep their mitre, as matplotlib's patches do; a line's markers are joined as the marker's shape says (MarkerStyle.get_joinstyle): the star bevelled, the rest as drawn
3-D walls grid light grey #E6E6E6, 1 pt (1.39 px), solid
Axis limits out at the outermost ticks (axes.autolimit_mode: round_numbers); an axis that names categories keeps its range, except a Gantt chart's rows, which round out as rows named by set_yticks do
Subplot gaps matplotlib's figure.subplot.wspace and hspace: 0.2 of the average axes between columns and between rows (GridSpec), wider only where what an axes draws needs the room
Quiver a quiver that names no scale has its arrows autoscaled to the axes' width (1 / (1.8 * max(10, sqrt(N))) of it for the mean vector), along the vector on the screen and drawn as filled polygons, the axes ranged over the tails and the arrows clipped to them (Axes.quiver); a scale you name is data units
Ticks pointing in, 4 pt long, 0.5 pt wide, labels 4 pt from the axis; marks on the top and right edges too, without labels
Log axis labels a view with a power of ten in it names the powers alone; with none, 2, 3, 4 and 6 times them (LogFormatter minor_thresholds (0, 0) in classic mode)
Tick spacing matplotlib's classic locator on a 2-D and a 3-D axis: nine intervals at most, steps of 1, 2, 5 and 10, whatever the axis' length, and the same steps round the axis' ends out; an axis that names a locator ends where that locator rounds it to (a MultipleLocator at its multiples, a log locator at decades; a FixedLocator keeps the data's ends)
Titles axes title 1.2 times the text (20 px), figure title the text's size, both normal weight
Colour map jet for a series that names none (image.cmap)
Fills FillBetween opaque with a black 1 pt edge and no line, as fill_between under patch.force_edgecolor
Patch edges a bar, a bin, a wedge, a fill and a shape of AddPatch edged in black 1 pt (patch.force_edgecolor, patch.edgecolor, patch.linewidth) unless the series names an edge; the edge and the hatch take the opacity given to the series, as matplotlib's alpha does, and a legend entry shows the patch at that opacity, a violin's body included
Charts with no axes a sparkline, a pie and the like are drawn on the figure's grey, with no white rectangle behind them (axis('off'); a Sankey diagram keeps its framed axes); a radar chart keeps the white patch of its web, as a polar axes does
Radar rings at the ticks of the theme's locator between 0 and the outer value, each labelled beside the first spoke, in the grid's stroke whether the grid is shown or not (black, dotted, 0.5 pt, 0.69 px), as the polar rings of this style are; the outer polygon is outlined as a frame, black, 1 pt
Scatter a marker with no colour or size of its own is blue and 20 points squared (4.5 points across), edged black 1 pt, and takes no colour of the cycle, as Axes.scatter does in classic mode; a 3-D scatter is 20 points squared too, every marker one size and none faded by its distance (axes3d.depthshade is off)
Colour cycles two, as matplotlib's axes keeps them: a line, a step, an error bar, a histogram, a stacked area and a violin take the next colour of the lines cycle, a bar, a pie's wedges and a fill the next of the patch cycle; a scatter and a fill between two curves take blue and a violin yellow, none of either cycle (classic mode); a stem, an event plot, a box plot, a quiver and every colour-mapped series take neither; a series given its colour moves no cycle; a second Y axis and the top X axis start both cycles again, as twinx and twiny do
Strip and swarm plots each group in its own colour of the cycle, from the first on (a frame given as columns, as seaborn's palette colours it), where the series names no colour; the dots of a swarm stand where seaborn's Beeswarm places them (pixels, lowest first, nearest the middle without touching), and the axes are padded by the 5 % of Axes.scatter
Box plot a blue box with blue dashed whiskers, black caps half the box wide, a red median, black + for the observations beyond the whiskers, a red square for the mean; 1 pt lines; takes no colour of the cycle (boxplot.*props); the boxes stand at 1, 2, ... each 0.15 of the span of the positions wide, at least 0.15 and at most 0.5 (0.45 for four), the axis ends half a unit past the outer boxes with no margin and the ticks stand at the boxes (a Positions or Widths you give is what is drawn)
Tick label offset taken off the labels and written once at the axis' end ("+1e2") when it saves two digits (axes.formatter.offset_threshold: 2)
Legend text 1.2 times the font (20 px, legend.fontsize: large), a square black frame 1 pt (1.39 px) wide, opaque (patch.linewidth, legend.framealpha: None), padded 0.4 of the legend's text size and standing 0.5 of it inside the corner of the axes (legend.borderpad, legend.borderaxespad), each row as tall as its own text and at least as tall as 'lp' (matplotlib's TextArea), the entries filling the columns in turn, each column standing on the baseline of its first row, the box as wide as the wider of its title and its entries, a title the size of the text in a normal weight; in a PNG the frame stands on the pixel grid, as matplotlib snaps it
Step-shaped lines in a PNG, a line of horizontal and vertical segments (a step, an ECDF, a Kaplan–Meier curve) of at most 1024 points stands on the pixel grid, as matplotlib's Agg backend snaps a line
Images square cells (image.aspect: equal), the axes box narrowed to the image's shape unless SetAspect or SetAspectAuto() says otherwise; shown at less than 3 times its size, a smoothed image is interpolated in its colours (image.interpolation_stage: auto); in a PNG the cells are one picture, with no seam between two cells
Polar axes each spoke label centred 11 pt out from the circle (the tick's pad and 7 pt, ThetaTick), the title at the top of the box (axes.titley: 1.0), a bar given no width 0.8 radians wide (Axes.bar)
Clipping the marks of every series cut off at the axes, with a limit or without one (clip_on), a chart of the library's own too (a treemap, a gauge, a Sankey diagram), but a pie, a donut and a table, which are drawn whole; a label, a value or a name is text and is never cut off (ax.text is clip_on False), except the labels of a contour, which are cut at the axes as its lines are (clabel gives each label the axes' box as its clip)
Cycle length 7 colors

Theme.MatplotlibV2 — the modern default

This theme uses a white background, black text and axis lines, the modern tab10 10-color cycle, DejaVu Sans at 10pt, and a grid that is hidden by default, as matplotlib's default style draws them (text.color, axes.edgecolor and xtick.color are black).

Plt.Create()
    .WithTheme(Theme.MatplotlibV2)
    .WithTitle("Modern matplotlib look")
    .AddSubPlot(1, 1, 1, ax => ax
        .Plot(x, y1, s => s.Label = "Quadratic")
        .Plot(x, y2, s => s.Label = "Linear")
        .WithLegend())
    .Save("v2.svg");

Color cycle — tab10

# Hex Name
0 #1f77b4 blue
1 #ff7f0e orange
2 #2ca02c green
3 #d62728 red
4 #9467bd purple
5 #8c564b brown
6 #e377c2 pink
7 #7f7f7f gray
8 #bcbd22 olive
9 #17becf cyan

At a glance

Property Value
Background #FFFFFF (white)
Axes background #FFFFFF (white)
Foreground text #000000 (black)
Font family DejaVu Sans, sans-serif
Font size 10.0pt
Grid hidden by default (Visible = false)
Grid when shown #B0B0B0, solid, 0.8 pt (1.11 px)
Minor grid the grid when shown, in its own stroke, on an axis whose minor ticks are on (a log or logit axis unless they are switched off)
Minor ticks off until switched on; a log or logit axis draws its own (2 to 9 times each power on a log axis) unless they are switched off; a linear step split in four, in five when it is 1, 2.5 or 5 times a power of ten (xtick.minor.ndivs: auto)
Grid's place over bars, fills, markers, patches and spans, under lines (axes.axisbelow: line, zorder 1.5)
Spines 0.8 pt (1.11 px)
Lines 1.5 pt (2.08 px) when the series is given no width
Dashes dashed 3.7, dotted 1 and 1.65, dash-dot 6.4, 1.6, 1 and 1.6, each length times the line's width (lines.scale_dashes: True), in the SVG and in the PNG
Line corners round (lines.solid_joinstyle) for every line, contour and streamplot lines included, and for the edge of what matplotlib draws as a collection (a scatter marker, a filled band, a violin, a hexbin, a 3-D face, a barb); a bar, a wedge and a box keep their mitre, as matplotlib's patches do; a line's markers are joined as the marker's shape says (MarkerStyle.get_joinstyle): the star bevelled, the rest as drawn
3-D walls the grid above
Axis limits where the data and the margin end (axes.autolimit_mode: data)
Subplot gaps matplotlib's figure.subplot.wspace and hspace: 0.2 of the average axes between columns and between rows (GridSpec), wider only where what an axes draws needs the room
Quiver a quiver that names no scale has its arrows autoscaled to the axes' width (1 / (1.8 * max(10, sqrt(N))) of it for the mean vector), along the vector on the screen and drawn as filled polygons, the axes ranged over the tails and the arrows clipped to them (Axes.quiver); a scale you name is data units
Ticks pointing out, 3.5 pt long, 0.8 pt wide, labels 3.5 pt past the mark; bottom and left edges
Log axis labels a view with one power of ten or none names 2, 3, 4 and 6 times them too, every multiple below 0.4 of a decade (LogFormatter minor_thresholds (1, 0.4))
Tick spacing matplotlib's default locator on a 2-D and a 3-D axis: as many intervals as the axis has room for, at most nine (one per three label sizes along X, one per two along Y; a 3-D axis counts along the width of its axes), steps of 1, 2, 2.5, 5 and 10, the smallest that covers the range
Titles axes and figure title 1.2 times the text (16.67 px), normal weight
Colour map viridis for a series that names none
Fills FillBetween opaque, no edge and no line, as fill_between
Patch edges none unless the series names an edge (patch.force_edgecolor off); a named edge 1 pt wide (patch.linewidth), a shape of AddPatch too, at the opacity given to the series with its hatch, as matplotlib's alpha does; a legend entry shows the patch at that opacity, a violin's body included
Scatter a marker is 36 points squared (6 points across) and stroked 1 pt in its own colour (scatter.edgecolors: face, patch.linewidth), so it is seven points across drawn; a 3-D scatter is 20 points squared, every marker one size, the farther ones fading down to 0.3 of their opacity (axes3d.depthshade)
Colour cycles two, as matplotlib's axes keeps them: a line, a step, an error bar, a histogram, a stacked area and a violin take the next colour of the lines cycle, a scatter, a bar, a pie's wedges and a fill the next of the patch cycle, so a scatter after a line is blue too; a stem, an event plot, a box plot, a quiver and every colour-mapped series take neither; a series given its colour moves no cycle; a second Y axis and the top X axis start both cycles again, as twinx and twiny do
Strip and swarm plots each group in its own colour of the cycle, from the first on (a frame given as columns, as seaborn's palette colours it), where the series names no colour; the dots of a swarm stand where seaborn's Beeswarm places them (pixels, lowest first, nearest the middle without touching)
Radar rings at the ticks of the theme's locator between 0 and the outer value, each labelled beside the first spoke, in the grid's stroke whether the grid is shown or not: #B0B0B0, solid, 0.8 pt (1.11 px); the outer polygon is outlined as a frame, black, 0.8 pt
Box plot a black box, black whiskers and caps half the box wide, a median in C1 (orange), the observations beyond the whiskers as open black circles 6 pt across, the mean a C2 triangle; 1 pt lines; takes no colour of the cycle (boxplot.*props); the boxes stand at 1, 2, ... each 0.15 of the span of the positions wide, at least 0.15 and at most 0.5 (0.45 for four), the axis ends half a unit past the outer boxes with no margin and the ticks stand at the boxes (a Positions or Widths you give is what is drawn)
Tick label offset written once at the axis' end ("+1e5") when it saves four digits (axes.formatter.offset_threshold: 4)
Legend text the font's size (13.89 px), a rounded light grey frame 1 pt (1.39 px) wide at 0.8 opacity, its outline too (patch.linewidth, legend.framealpha: 0.8), padded 0.4 of the legend's text size and standing 0.5 of it inside the corner of the axes (legend.borderpad, legend.borderaxespad), each row as tall as its own text and at least as tall as 'lp' (matplotlib's TextArea), the entries filling the columns in turn, each column standing on the baseline of its first row, the box as wide as the wider of its title and its entries, a title the size of the text in a normal weight; in a PNG the frame stands on the pixel grid, as matplotlib snaps it
Step-shaped lines in a PNG, a line of horizontal and vertical segments (a step, an ECDF, a Kaplan–Meier curve) of at most 1024 points stands on the pixel grid, as matplotlib's Agg backend snaps a line
Images square cells (image.aspect: equal), the axes box narrowed to the image's shape unless SetAspect or SetAspectAuto() says otherwise; shown at less than 3 times its size, a smoothed image is interpolated in its colours (image.interpolation_stage: auto); in a PNG the cells are one picture, with no seam between two cells
Polar axes each spoke label centred 14 pt out from the circle (the tick's pad and length and 7 pt, ThetaTick), the title over the highest label (axes.titley: None), a bar given no width 0.8 radians wide (Axes.bar)
Clipping the marks of every series cut off at the axes, with a limit or without one (clip_on), a chart of the library's own too (a treemap, a gauge, a Sankey diagram), but a pie, a donut and a table, which are drawn whole; a label, a value or a name is text and is never cut off (ax.text is clip_on False), except the labels of a contour, which are cut at the axes as its lines are (clabel gives each label the axes' box as its clip)
Cycle length 10 colors

In 3-D

Under both themes a 3-D box is drawn as matplotlib draws it. The walls carry the grid in its own colour, width and line style (the light grey 1 pt grid of the classic style, the v2 grid above), and a Surface or Trisurf given no opacity is opaque, as matplotlib's plot_surface and plot_trisurf draw it; every other theme draws such a surface at 0.8. A surface that leaves ShowWireframe alone and names no edge colour has no outline under v2 and a black 1 pt outline under classic, as matplotlib draws it in each style (every other theme outlines it in a thin translucent black). ShowWireframe = true outlines it under any theme, in black 1 pt under these two, an edge colour you set is drawn 1 pt wide, and ShowWireframe = false draws no outline under any theme. The box is bounded by one axis line per axis along the edge its ticks stand on, in the theme's text colour, 0.8 pt wide under v2 and 0.75 pt under classic, as matplotlib draws its 3-D axis lines; every other theme bounds the back panes with nine thin grey edges instead. The walls carry a line at every tick in view, the ones on the ends of an axis included, and at every minor tick of an axis that has its minor ticks on, as matplotlib's 3-D walls do (every other theme draws major lines only, none on an end of an axis, where it draws its edges). Under any theme that names no pane colour, each back pane wears matplotlib's grey of its axis: #F8F8F8 for the X wall, #F2F2F2 for the Y wall and #F5F5F5 for the floor.


Opting into a grid

Both themes ship with the grid off, matching matplotlib's plt.grid(False) default.

using MatPlotLibNet;
using MatPlotLibNet.Styling;

double[] x = [0, 1, 2, 3, 4, 5];
double[] y = [0, 1, 4, 9, 16, 25];

Plt.Create()
    .WithTheme(Theme.MatplotlibV2)
    .AddSubPlot(1, 1, 1, ax => ax
        .Plot(x, y)
        .ShowGrid(true))                           // simple toggle
    .Save("v2_with_grid.svg");

Or override the theme grid via ThemeBuilder:

using MatPlotLibNet.Styling;

var v2WithGrid = Theme.CreateFrom(Theme.MatplotlibV2)
    .WithGrid(g => g with { Visible = true, Color = Color.FromHex("#B0B0B0") })
    .Build();

Comparison

Aspect MatplotlibClassic MatplotlibV2 Theme.Default
Era mimicked matplotlib < 2.0 matplotlib 2.0+ none specifically
Cycle bgrcmyk (7) tab10 (10) tab10 (10)
Foreground text pure black pure black pure black
Font size 12pt 10pt 13pt (default)
Grid default off off on
Legend default upper right best (least covered) best (least covered)
Use case retro / classic modern Jupyter look MatPlotLibNet's own default

Theme.Default already uses tab10. Choose MatplotlibV2 when you want the full matplotlib look: it has a different font stack, matplotlib's sizes for titles and ticks, axes that end where their data ends, and a grid that is hidden by default.


Community Themes

There are six community themes. Each has its own palette, font, size, and grid defaults. Applying one visibly changes the chart; no other API calls are needed.

Theme Palette Font Size Grid
Theme.Grayscale grayscale cycle (no hues) default default default
Theme.Paper default serif 11pt off
Theme.Presentation default bold 16pt default
Theme.Poster default bold 20pt on, 1.5 linewidth
Theme.GitHub GitHub brand palette default default #E1E4E8
Theme.Minimal default default 11pt off

Use them the same way: Plt.Create().WithTheme(Theme.Paper)…. Contract tests check that each theme produces byte-distinct output, so a theme that collapses back to Default fails CI.


Pixel-verified against matplotlib

Every chart with a matplotlib equivalent is verified against a pinned matplotlib (3.11.2) reference PNG under both themes; the fidelity suite runs every fixture twice, once per theme:

# regenerate reference PNGs (developers only — not run in CI)
pip install -r tools/mpl_reference/requirements.txt
python tools/mpl_reference/generate.py --all --style both

# run the dual-theme fidelity tests
dotnet run --project Tst/MatPlotLibNet.Fidelity/MatPlotLibNet.Fidelity.Tests.csproj

Each test renders one MatPlotLibNet figure to PNG with the SkiaSharp backend and compares it against the matplotlib reference using three metrics: RMS pixel error, block SSIM, and MaxColorDeltaE (CIE ΔE*76 from the reference's 5 dominant colours to the nearest colour the PNG holds at least a tenth as much of). Failures emit a 3-panel side-by-side diff PNG (reference | actual | abs-difference heatmap) under bin/<configuration>/net10.0/fidelity-failures/{theme}_{name}.diff.png.

Coverage: the fixtures are the core charts (line, scatter, bar, hist, pie, box, violin, heatmap, contour, polar, candlestick, errorbar), every series family (XY, grid, field, polar, categorical, distribution, 3D, financial, special), the technical indicators (checked against pandas_ta), the axes features (broken and symmetric-log axes, linked axes, spine bounds, patches, bar labels, annotations), maps (cartopy), ternary plots (mpltern), and a composition (a multi-subplot suptitle, mathtext labels, and a mathtext legend).

The v2 fixtures use plt.style.context('default'), which is matplotlib's modern default (tab10 cycle, DejaVu Sans 10pt, black text and axis lines). This is the look that Theme.MatplotlibV2 reproduces. Each picture is saved with its style still in force, as a script that calls plt.style.use and then savefig draws it, so the settings matplotlib reads only when it draws (where a classic axis ends, the offset of a tick label, the text hinting) are the style's; the figure keeps its own colour, the classic grey that Theme.MatplotlibClassic draws.


Implementation notes

An internal MatplotlibThemeFactory builds both themes through a shared Build(...) helper, so the two themes differ only where they have to: color cycle, font size, and foreground text. The font stack is a record struct (MatplotlibFontStack). It has named fields with value equality; it is not a positional tuple.


See also

MatPlotLibNet 1.30.0

On the docs site

Clone this wiki locally