Repository navigation
International Text
Labels, titles and legend entries can be written in any script. Arabic and Hebrew work out of the box. Other scripts need a font file that has their letters, registered once at startup.
Write the text in reading order, as you would type it:
using MatPlotLibNet;
using MatPlotLibNet.Skia;
var figure = Plt.Create()
.WithTitle("درجة الحرارة")
.AddSubPlot(1, 1, 1, ax =>
{
ax.Plot([1, 2, 3, 4], [12.5, 14.0, 13.2, 15.1], s => s.Label = "תל אביב");
ax.Plot([1, 2, 3, 4], [9.8, 11.2, 10.5, 12.0], s => s.Label = "Amsterdam");
ax.WithLegend();
})
.Build();
File.WriteAllBytes("international.png", figure.ToPng());The library runs the Unicode bidi algorithm to find the reading direction of every character. It cuts the text into runs where the direction or the script changes, shapes each run with HarfBuzz, and lays the runs out in visual order. Arabic letters join, Hebrew reads right to left, a number inside an Arabic line keeps its digits in order, and the library places a Latin word next to an Arabic one where a reader expects it. The bidi algorithm is checked against Unicode's own test files: 861,948 cases.
Text measurement, the glyph outlines in an SVG, and the pixels in a PNG or PDF all come from the same shaping pass.
The packages that render SVG without MatPlotLibNet.Skia (Blazor, ASP.NET Core, GraphQL, Interactive, Notebooks,
DataFrame, Geo) write <text> elements, and the browser shapes them. The library marks a right-to-left label with
direction="rtl" so the browser places its punctuation correctly. Alignment is always geometric, not
script-relative: TextAlignment.Left is the left edge in every script.
DejaVu Sans, the bundled font, has no Devanagari, Thai, Chinese, Japanese or Korean glyphs. Register a font file and use its family name:
using MatPlotLibNet.Skia;
using MatPlotLibNet.Styling;
var font = SkiaFonts.Register("fonts/NotoSansDevanagari-Regular.ttf");
var theme = Theme.CreateFrom(Theme.Seaborn).WithFont(f => f with { Family = font.Family }).Build();Register returns the family name, weight and slant the file declares. Registering the same face twice throws an
exception. A font installed on the machine works by name without registration.
If the library cannot find the family anywhere, the chart uses the operating system's default face and reports the
family name once through ChartDiagnostics.Emitted.
Set MATPLOTLIBNET_FONTS to font files or directories of font files, separated by ;, in the server's
environment. They are registered when dnx MatPlotLibNet.Mcp starts.
Shaping applies the font's kerning to Latin text too. In DejaVu Sans at 13 px, kerning made "Ta" 2.15 px narrower than the same pair without kerning, and it made "AV" 0.85 px narrower. Widths and positions move by that much, and charts match matplotlib's own output more closely.
-
MatPlotLibNet.Mauidraws text through the platform's text engine. - The bundled font covers Latin, Greek, Cyrillic, Arabic and Hebrew; other scripts need a registered font.
See the cookbook page for the full example.
MatPlotLibNet 1.26.0
- Home
- Getting Started
- Fluent Cheatsheet
- Examples — each release in code
-
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