A native .NET 10 port of Matplotlib — the de-facto 2D plotting library for Python — rebuilt in idiomatic F# following Object-Oriented and Domain-Driven Design principles.
A faithful port of Matplotlib's plotting model (
Figure/Axes/Artist/Transform/Backend) with a familiarpyplot-style facade, producing publication-quality output with zero native dependencies — pure-managed SVG, PNG and PDF backends.
![]() imshow + colorbar (viridis) |
![]() contour (marching squares) |
![]() annotate + text |
![]() line collections |
dotnet add package DotnetMatplotlibopen Matplotlib
let plt = Pyplot()
plt.Plot([| 1.0; 2.0; 3.0; 4.0 |], [| 1.0; 4.0; 9.0; 16.0 |], color = "C0", label = "y = x^2")
|> ignore
plt.Title "Hello, dotnet-matplotlib"
plt.XLabel "x"
plt.YLabel "y"
plt.Legend()
plt.Savefig "hello.svg"Savefig chooses the format from the file extension. SVG, PNG and PDF are
all pure-managed and cross-platform (zero native dependencies):
plt.Savefig "plot.svg" // vector SVG
plt.Savefig "plot.png" // raster PNG (software rasterizer, anti-aliased)
plt.Savefig "plot.pdf" // vector PDFText uses TrueType fonts discovered from the system. To select a font, set the
default family before plotting — the equivalent of Matplotlib's
rcParams["font.family"]:
plt.FontFamily <- "serif"Animations are written as looping GIFs:
// factory builds the Figure for each frame index
plt.SaveGif("wave.gif", 30, (fun i -> buildFrame i), fps = 20)Figures can also be shown in a live window — the equivalent of Matplotlib's
plt.show(). This is an opt-in, Windows-only backend (WinForms + GDI+) that
lives in Matplotlib.Gui, so the default path stays free of any UI dependency:
open Matplotlib
open Matplotlib.Gui // adds plt.Show()
let plt = Pyplot()
plt.Plot([| 0.0; 1.0; 2.0; 3.0 |], [| 0.0; 1.0; 4.0; 9.0 |], color = "C0") |> ignore
plt.Title "Hello, window"
plt.Show() // opens a window and blocks until it is closed; resizes re-layoutIn a .NET Interactive / Polyglot / Jupyter notebook, figures render inline as SVG:
#r "nuget: DotnetMatplotlib.Interactive"
open Matplotlib
Matplotlib.Interactive.Notebook.register () // once per session
let plt = Pyplot()
plt.Plot([| 0.0; 1.0; 2.0 |], [| 0.0; 1.0; 4.0 |], color = "C0") |> ignore
plt // the cell value renders as an inline SVG plotBecause the library is pure-managed, it runs in the browser via .NET WebAssembly — no JavaScript charting library and no native dependencies. The standalone Blazor WASM demo renders plots as inline SVG client-side:
dotnet run --project samples/BlazorDemoPlot directly from a Microsoft.Data.Analysis.DataFrame (pandas .plot() style):
dotnet add package DotnetMatplotlib.DataFrameopen Matplotlib.DataFrame // adds df.PlotLine / PlotScatter / PlotBar / PlotHist
df.PlotLine("x", "y").Savefig "line.png"
df.PlotHist("value", 20).Savefig "hist.svg"Each method plots the named column(s) and returns the Pyplot, so you can add a
title or choose the output format. The same extension methods work from C#.
DotnetMatplotlib.Mcp is a Model Context Protocol
server that lets AI agents create plots with this library. Install it as a .NET
tool and point your MCP client at the matplotlib-mcp command:
dotnet tool install -g DotnetMatplotlib.Mcp{
"mcpServers": {
"matplotlib": { "command": "matplotlib-mcp" }
}
}It exposes plot_line, scatter, bar and heatmap tools that render to a
PNG / SVG / PDF file (chosen by the output extension) and return the saved path.
- Plots:
plot,scatter,bar/barh,fill_between,step,errorbar,stem - Statistics & fields:
hist2d,boxplot,violinplot,quiver,streamplot - Images:
imshow,pcolormeshwith colormaps (viridis,gray,jet,hot) andcolorbar - Contours:
contour(marching squares),contourf - Patches & line/poly collections, hatching, the full marker set
- Legends (including automatic
bestplacement), text & annotations - Subplots with
tight_layout/constrained_layout - Scales: linear / log / symlog / logit; categorical & date axes
- 3D:
plot3D,scatter3D,plot_wireframe - Style sheets and
rcParamsparsing (ggplot,dark_background, …) - Backends: SVG, PNG and PDF (pure-managed), an interactive window (Windows), and animated GIF
- Integrations:
Microsoft.Data.AnalysisDataFrames, .NET Interactive / Jupyter notebooks, an MCP server for AI agents, and Blazor WebAssembly (runs in the browser)
See PORTING.md for the parity log.
Requires the .NET 10 SDK.
dotnet tool restore # Fantomas (one-time)
dotnet build # whole solution (warnings are errors)
dotnet test # all tests
dotnet run --project samples/Gallery -- out # render the sample gallery to ./outCode style is enforced with Fantomas; the lint configuration is described in LINTING.md.
dotnet-matplotlib is released under the MIT license — see LICENSE.
Hunter, J. D. (2007). Matplotlib: A 2D graphics environment. Computing in Science & Engineering, 9(3), 90–95. https://doi.org/10.1109/MCSE.2007.55



