Skip to content

Leave missing data out of the picture; clip far-off geometry - #86

Merged
certik merged 1 commit into
mainfrom
split-2-missing-data
Nov 22, 2026
Merged

certik merged 1 commit into
mainfrom
split-2-missing-data

Conversation

@certik

@certik certik commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Missing data and far-off geometry in the plotting layer

A NaN or an infinity in plotted data is missing data to matplotlib: a line breaks around it, and a bar, marker or label placed at one is left out. On main, only plot dropped it; bar, errorbar, boxplot, contourf, axvline, text and most other plot types handed it to the backends, which wrote NaN into SVG and PDF.

  • One way in. Every renderer call of the plotting layer now goes through put_path, put_rect, put_circle, put_markers, put_glyphs and put_image in fplotlib_artist.
    • They leave out what is missing, as matplotlib's path handling does.
    • They clip geometry far outside the view to a box ten canvases out, plus what a stroke can reach. A fill value of 1e30 under a ylim, or a line a million points long, is drawn where it crosses the view.
    • Strokes and fills are clipped separately, and a dash pattern keeps its phase across a cut.
    • Line widths and dash lengths past 1e12 points are drawn as 1e12, which covers anything that can be seen just as fully.
    • A call with nothing missing or far away reaches the renderer unchanged. The only test pictures that change are hist_orient's SVG, PDF and EPS: its log-scale bars are 129,507 points tall, and are now cut at the clip box. The picture looks the same.
  • Plot types.
    • hist, hist2d, hexbin and pie leave missing values out of their bins and wedges.
    • streamplot ends a line where the field is missing.
    • 3D limits take only finite values, and an axis whose every value is missing has no ticks.
    • An axes or colorbar that a layout leaves no room for is not drawn.
    • add_secondary copies its parent, which a caller may pass as cur_i.

tests/test_missing.f90 renders 74 plots with NaN, infinite or far-off values in all four formats, and also into a renderer that records how far out anything is drawn. None may stop, nothing may be drawn past the clip box, and no NaN or infinity may reach the SVG, the EPS or the PDF page.

This is part of a stack of five PRs that together are exactly #83 (the final tree of the last one is byte for byte #83's), split so that each can be reviewed and merged on its own. Each one builds and passes the whole test suite with gfortran, gfortran -O3 -march=native, flang, flang -O3 -march=native and LFortran, and the docs build.

  1. PNG rasterizer: exact and bounded on far-off geometry #85 PNG rasterizer: exact and bounded on far-off geometry
  2. Leave missing data out of the picture; clip far-off geometry #86 Missing data and far-off geometry in the plotting layer
  3. Stop on broken preconditions; return run-time failures in status_t #87 Contract stops and status_t (the error API)
  4. Check every plotting argument from one generated table #88 Argument checks from one generated table
  5. Keep far-off data finite in ticks, dates, contours and axis limits #89 Far-off data in ticks, dates, contours and axis limits; sanitizer CI job

Merge them in order; each PR's base is the one before it. #83 went through 30 rounds of independent review, the last with no blockers.

A NaN or an infinity in plotted data is missing data to matplotlib: a
line breaks around it, and a bar, marker or label placed at one is left
out. Only plot dropped it before; bar, errorbar, boxplot, contourf,
axvline, text and most other plot types handed it to the backends,
which wrote NaN into SVG and PDF.

Every renderer call of the plotting layer now goes through put_path,
put_rect, put_circle, put_markers, put_glyphs and put_image in
fplotlib_artist. They leave out what is missing as matplotlib's path
handling does, and clip geometry far outside the view to a box ten
canvases out, plus what a stroke can reach, so that a fill value of 1e30
under a ylim, or a line a million points long, is drawn where it crosses
the view. Strokes and fills are clipped separately, a dash pattern keeps
its phase across a cut, and line widths and dash lengths past 1e12
points are drawn as 1e12, which covers anything that can be seen just as
fully. A call with nothing missing or far reaches the renderer
unchanged, so every existing picture is the same.

hist, hist2d, hexbin and pie leave missing values out of their bins and
wedges, streamplot ends a line where the field is missing, 3D limits
take only finite values, an axis whose every value is missing has no
ticks, and an axes or colorbar a layout leaves no room for is not drawn.
add_secondary copies its parent, which the caller may pass as cur_i.

tests/test_missing.f90 renders 74 plots with NaN, infinite or far-off
values in all four formats, and into a renderer that records how far out
anything is drawn; none may stop, and no NaN or infinity may reach the
SVG, the EPS or the PDF page.
@certik
certik added this pull request to stack #90 November 22, 2026 20:35
Base automatically changed from split-1-raster to main November 22, 2026 20:36
@certik
certik merged commit 5eda893 into main Nov 22, 2026
10 checks passed
@certik
certik deleted the split-2-missing-data branch November 22, 2026 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant