Repository navigation
Contributing
- .NET 10 SDK
- Visual Studio 2022 / VS Code / JetBrains Rider
- Git
# Fork the repo on GitHub, then:
git clone https://github.com/<your-username>/MatPlotLibNet.git
cd MatPlotLibNet
git checkout -b feature/your-feature-nameSrc/ Source projects (one folder per package)
MatPlotLibNet/ Core — models, fluent API, SVG renderer, JSON
MatPlotLibNet.Skia/ PNG/PDF/GIF export
MatPlotLibNet.Blazor/
...
Tst/ Test projects — mirrors Src/ layout exactly
MatPlotLibNet/
MatPlotLibNet.Skia/
...
Samples/ Runnable example projects
Benchmarks/ BenchmarkDotNet performance suite
Every Src/X folder has a matching Tst/X folder. Every new public class, method, or record gets at least one test.
dotnet build MatPlotLibNet.CI.slnf -c ReleaseThis is the solution filter CI builds. A bare dotnet build in the repository root takes the full
MatPlotLibNet.slnx, which also holds the Maui head and so needs the Maui workload installed. A build ends with
0 warnings and 0 errors.
Tests use xUnit v3 compiled as .NET 10 executables. Use dotnet run, not dotnet test:
# Core unit tests
dotnet run --project Tst/MatPlotLibNet/MatPlotLibNet.Tests.csproj
# One test class (the built executable takes an xunit filter)
Tst/MatPlotLibNet/bin/Release/net10.0/MatPlotLibNet.Tests.exe -filter "/*/*/LegendTests/*"
# The other packages each have a suite of their own, run the same way:
dotnet run --project Tst/MatPlotLibNet.Geo/MatPlotLibNet.Geo.Tests.csproj
dotnet run --project Tst/MatPlotLibNet.Skia/MatPlotLibNet.Skia.Tests.csproj
dotnet run --project Tst/MatPlotLibNet.Blazor/MatPlotLibNet.Blazor.Tests.csproj
dotnet run --project Tst/MatPlotLibNet.Avalonia/MatPlotLibNet.Avalonia.Tests.csproj
dotnet run --project Tst/MatPlotLibNet.AspNetCore/MatPlotLibNet.AspNetCore.Tests.csproj
dotnet run --project Tst/MatPlotLibNet.Interactive/MatPlotLibNet.Interactive.Tests.csproj
dotnet run --project Tst/MatPlotLibNet.GraphQL/MatPlotLibNet.GraphQL.Tests.csproj
dotnet run --project Tst/MatPlotLibNet.DataFrame/MatPlotLibNet.DataFrame.Tests.csproj
dotnet run --project Tst/MatPlotLibNet.Mcp/MatPlotLibNet.Mcp.Tests.csproj
dotnet run --project Tst/MatPlotLibNet.Verso/MatPlotLibNet.Verso.Tests.csproj
# Every C# block of this wiki, compiled (needs the wiki cloned beside the repository)
git clone https://github.com/xkqg/MatPlotLibNet.wiki.git ../MatPlotLibNet.wiki
dotnet run --project Tst/MatPlotLibNet.Wiki/MatPlotLibNet.Wiki.Tests.csproj
# Matplotlib fidelity tests (CI runs them too)
dotnet run --project Tst/MatPlotLibNet.Fidelity/MatPlotLibNet.Fidelity.Tests.csprojCI runs the core suite, the package suites above, the wiki suite and the fidelity suite. The Wpf, Uno and Maui heads need Windows
or a workload, so the windows-heads job of ci.yml builds them and runs their suites. Run the fidelity suite yourself when you
change how something is drawn.
Every class has to clear the strict per-class coverage gate of at least 90 % line and 90 % branch coverage. The gate
is run with tools/coverage/run.ps1 -Check -Strict, and docs/COVERAGE.md
holds the per-namespace breakdown.
SVG interaction scripts (legend drag, treemap drilldown, pan/zoom, etc.) are tested against a Jint-backed DOM stub in Tst/MatPlotLibNet/Rendering/Svg/Interaction/. InteractionScriptHarness.FromBuilder(b => …) builds a figure, runs its embedded scripts, then dispatches synthetic events and asserts DOM mutations.
What the harness DOES simulate:
- Capture-phase ordering on
addEventListener(true/{ capture: true }); capture listeners fire before bubble listeners, in registration order -
stopPropagation()halts the in-flight dispatch in both phases -
document.elementFromPoint(x, y)via the test-injectableDomDocument.StubElementFromPoint -
document.currentScriptso multi-chart pages route their scripts correctly
What the harness does NOT simulate:
- Cross-element event bubbling —
Firewalks listeners on the literal target only; tests needing delegation must fire directly at the element that owns the listener -
setPointerCapturetarget redirection — the stub is a no-op (useStubElementFromPointto model the redirected click) - A real layout engine (no
getBBox/getBoundingClientRectmath beyond a synthetic constant)
Sample drag-test pattern (mirrors LegendDragTests.Drag_LegendItem_TranslatesLegendGroup_BeyondThreshold):
using var h = InteractionScriptHarness.FromBuilder(b => b
.WithLegendToggle()
.Plot([1.0, 2.0, 3.0], [4.0, 5.0, 6.0], s => s.Label = "A"));
h.Simulate("[data-legend-index='0']", "pointerdown", e => { e.clientX = 50; e.clientY = 50; });
h.Simulate("[data-legend-index='0']", "pointermove", e => { e.clientX = 110; e.clientY = 70; });
h.Simulate("[data-legend-index='0']", "pointerup", e => { e.clientX = 110; e.clientY = 70; });
var legend = h.Document.querySelector("g.legend")!;
Assert.Contains("translate(60,20)", legend.getAttribute("transform") ?? "");The fidelity suite compares MatPlotLibNet's PNG output against PNGs drawn by a pinned matplotlib (3.11.2). To regenerate them:
pip install -r tools/mpl_reference/requirements.txt
python tools/mpl_reference/generate.py --all --style bothFixtures are written under Tst/MatPlotLibNet.Fidelity/Fixtures/Matplotlib/{classic,v2}/{name}.png, with a json beside each that names the matplotlib version that drew it; --chart <name> writes only the charts named, and --out <dir> writes the same layout elsewhere, to compare a run with what is checked in. The generator is not run in CI: a reference is drawn again when matplotlib's version or the chart's script changes, never to follow a change of the library's drawing. A package a chart needs that is not installed stops the generator; it never draws a substitute picture.
Each fidelity test draws one chart to a PNG with SkiaSharp, straight from the figure (never through the SVG writer), and runs three independent metrics against the matplotlib reference:
- RMS — root-mean-square pixel error (0–255 scale)
- SSIM — block structural similarity (0–1, higher is better)
- MaxColorDeltaE — CIE ΔE*76 from each of the reference's 5 dominant colours to the nearest colour the PNG holds at least a tenth as much of (catches palette drift; a colour under one pixel in a thousand, such as the grey at the edge of a glyph, is no palette colour, so the same picture reads the same on Windows and on Linux)
Each test states its limits for each style, the worst score the style measures on Windows and on Linux plus a small margin. On failure, a 3-panel side-by-side diff PNG (reference, actual, absolute-difference heatmap) is written under bin/<configuration>/net10.0/fidelity-failures/{theme}_{name}.diff.png for visual triage.
| Rule | Detail |
|---|---|
| Records | Prefer record / record struct for immutable data types |
No Base suffix |
Abstract classes get descriptive names, not XyzBase
|
| DRY generics | Use stacked base classes, where each layer adds the behaviour for one specific case: Indicator is the base of CandleIndicator<T> and PriceIndicator<T>, ChartSeries is the base of OhlcSeries and DatasetSeries, and SeriesRenderer holds the shared helpers |
| Fluent API | Public builders chain with return this — keep the API intuitive and discoverable |
| No statics for shared behavior | Prefer a generic base class with overrides over static utility methods |
| Minimal error handling | Only validate at system boundaries (user input, external APIs) |
| No speculative abstractions | Build exactly what the task requires |
- Pick the right base class:
ChartSeries(generic),XYSeries(X/Y data),OhlcSeries(financial OHLC),DatasetSeries(multi-dataset distribution). - Add the class to
Src/MatPlotLibNet/Models/Series/in the appropriate family folder. ImplementISeriesSerializable.ToSeriesDto()and a staticFromSeriesDto(Axes, SeriesDto)factory on the series itself, following the Information Expert pattern: the series serializes and deserializes itself. - Add a renderer in
Src/MatPlotLibNet/Rendering/SeriesRenderers/— useColor.WithOpacity(opacity)for an opacity,ApplyDownsampling(x, y, maxPoints)for XY data. - Say what the kind is to matplotlib once, in its
Artistoverride (the call its colour is asked with, its z-order and the look that colours it), and hand a renderer values, not rules: a caller's line width and dash are held as oneGivenStrokewith the kind'sLineWidthRule, a bar-like patch implementsIEdgedPatchfor its edge, and a theme's numbers are read from its looks. A renderer asks the owner of a rule and never works the rule out again (the repository's CONTRIBUTING.md, "One owner per rule, and a difference is a value"). - Add the verb of the axes (
Axes<Family>Verbs) and, beside it, the verb of the builder: anextension(AxesBuilder axes)member ofAxesBuilder<Family>Verbsin the same family folder, which adds the series through the axes verb and hands it to the caller's callback (axes.Configured(...)).AxesBuilderitself takes no new method. - Add tests in
Tst/MatPlotLibNet/. - Register the discriminator in
SeriesRegistry.RegisterDefaults()with oneRegister("discriminator", MySeries.FromSeriesDto)line; this gives the series JSON round-trip support. The registry is the only other file a new series kind touches for serialization, so there is no central switch that grows with every series.
- Pick the right base class:
CandleIndicator<T>(needs OHLCV),PriceIndicator<T>(needs single price array), orIndicator<T>(other). - Add the class to
Src/MatPlotLibNet/Indicators/. - Implement
Compute()— use base helpers:ComputeTrueRange(),ComputeTypicalPrice(),ComputeDonchianMid(period). - Implement
Apply(axes)— draw through the base:PlotLine(axes, values)for a line,PlotBand(axes, result, alpha)for a band,Positions(count)for anything else (a histogram, an area, dots). The base puts each value at the bar it is worked out at, the last at the last bar, so an indicator never types a warm-up; one that holds its own input instead of deriving fromCandleIndicator<T>orPriceIndicator<T>says how many bars it was given (BarsIn). An indicator whose values live in a fixed range (an RSI's 0 to 100) states it once as aPaneRange(its staticPane) and pins its pane withPane.Pin(axes); its streaming form reads the samePane.IndicatorContractTestsholds every indicator to both. - Say the defaults, the label and the checks once. Every default of a parameter is a
public const Default<Parameter>on the class (Rsi.DefaultPeriod); aninternal static IndicatorSpec Spec(...)checks the parameters (ThrowIfBelowand its kin) and returns the label, the labels of the lines and the first value. The constructor takes itsLabelfrom it, and a streaming form passes it to its base, which makes and labels its output lines and reads its warm-up from it.IndicatorSurfaceContractTestsholds every way to reach the indicator to both. - Add the verb of the builder to the indicator class that matches what the indicator draws (
AxesBuilderIndicatorVerbsfor an overlay on the prices,AxesBuilderOscillatorVerbs,AxesBuilderVolumeIndicatorVerbs,AxesBuilderVolatilityIndicatorVerbs, inSrc/MatPlotLibNet/Indicators/), ending inApplyIndicator, which places the indicator through the axes and centres it on the bar slots of a candlestick or bar panel. - Add tests in
Tst/MatPlotLibNet/Indicators/.
The repository has five GitHub Actions workflows. Three of them are the ones a contribution meets:
| Workflow | Trigger | What it does |
|---|---|---|
ci.yml |
Every push / PR | Restore, build, and run all test suites via dotnet run
|
publish.yml |
release: [published] |
Packs every package in MatPlotLibNet.CI.slnf and pushes them to NuGet. The package count is whatever the filter carries; a test checks that every packable project is published by some workflow |
release.yml |
push: tags: v* |
Creates a GitHub Release with auto-generated notes |
The other two publish the documentation site (pages.yml) and the MCP server to the MCP registry
(publish-mcp-registry.yml).
The CI solution filter MatPlotLibNet.CI.slnf covers all cross-platform packages, including MatPlotLibNet.Mcp. MatPlotLibNet.Maui requires Windows runners and is packed by the platform job instead.
Adding a new package: you must add both the Src/ and Tst/ .csproj paths to MatPlotLibNet.CI.slnf, and add the test runner line to publish.yml, otherwise the package will never be packed or published.
- Keep PRs focused on a single change.
- Include tests for all new functionality.
- Ensure all existing tests pass before opening the PR.
- Update the package's
README.mdif the change affects the public API. - Leave
<Version>alone: the maintainer names the version and sets it in every.csprojand in the MCP manifest at once. - CI must be green before merge — do not merge with failing checks.
Use GitHub Issues.
For bugs, include:
- Steps to reproduce
- Expected vs. actual output
- .NET version and OS
By contributing, you agree that your contributions will be licensed under the MIT License.
MatPlotLibNet 1.30.0
- Home
- Getting Started
- Fluent Cheatsheet
- Examples — each release in code
- Migrating to 1.30.0 — what was removed and what takes its place
-
Package Map
- MatPlotLibNet — the core package
- Chart Types
- Styling
- Advanced
- Streaming
- Bidirectional SignalR
- Interactive Controls
- MCP Server
- Verso
- Notebooks
- Accessibility
- International Text
- Benchmarks
- Roadmap
- Contributing
On the docs site
- Playground — try a chart in the browser
- Cookbook — copy-paste code with its picture
- API reference — every public type and member