#5260·ScottPlot

Polygon FillHatch / FillHatchColor not rendered when FillColor is transparent

Author: pbandykCreated Jul 30, 2026Updated Jul 30, 2026

Summary

When a Polygon's FillColor is transparent, its FillHatch + FillHatchColor are not rendered, even though those properties are independent on the FillStyle. Setting an opaque FillHatchColor should be sufficient to draw the hatch lines regardless of FillColor's alpha. The expected idiom — outline + hatch with no backdrop fill — is common in scientific plots (matplotlib calls this facecolor='none', hatch='/').

The legend swatch for the same polygon is also blank in this configuration, which I expect to look like a miniature of the polygon's rendered appearance (outline + hatch).

Repro

csharp
using ScottPlot;

var plot = new Plot();
var poly = plot.Add.Polygon(new Coordinates[]
{
    new(0, 0), new(10, 0), new(10, 10), new(0, 10),
});
poly.LineColor       = Colors.Black;
poly.LineWidth       = 2;
poly.FillColor       = Colors.Transparent;                  // no backdrop fill
poly.FillHatch       = new ScottPlot.Hatches.ForwardDiagonal();
poly.FillHatchColor  = Colors.Red.WithAlpha(0.8f);          // we want this visible
poly.LegendText      = "hatched region";
plot.ShowLegend();
plot.SavePng("hatch-without-fill.png", 400, 400);

Expected

  • Polygon interior shows red diagonal hatch lines.
  • Black outline around the polygon.
  • Legend swatch shows the same: outline + diagonal hatch over a transparent background.

Actual

  • Polygon interior is empty (hatch not drawn).
  • Black outline renders correctly.
  • Legend swatch is blank.

Setting FillColor to any non-transparent color makes the hatch appear, which suggests the render path short-circuits on FillColor.Alpha == 0 before consulting the hatch fields.

Matplotlib equivalent (works as expected)

python
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon

fig, ax = plt.subplots()
ax.add_patch(Polygon([(0, 0), (10, 0), (10, 10), (0, 10)],
                     facecolor='none', edgecolor='black',
                     hatch='/', linewidth=2,
                     label='hatched region'))
ax.set_xlim(-1, 11); ax.set_ylim(-1, 11)
ax.legend()
plt.savefig('hatch-without-fill.png')

This renders outline + diagonal hatch (and a matching legend swatch).

Environment

  • ScottPlot 5.1.58 (ScottPlot.Avalonia 5.1.58 — same render path)
  • .NET 8
  • Windows 11

Workaround (in case anyone else hits this)

Generate hatch geometry yourself with a scan-line / point-in-polygon pass and add it as separate LinePlot / Markers plottables. Works, but means the hatch is its own plottable rather than a property of the polygon, so it has to be tracked separately for legend / hit-testing purposes.