Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c40d78e
Hand out axes handles from subplots
certik Aug 15, 2026
081c641
Add style sheets and rcParams
certik Aug 15, 2026
54be24b
Add spans and line runs
certik Aug 15, 2026
ad6fff1
Complete the bar charts
certik Aug 15, 2026
4722e7b
Complete the histograms
certik Aug 15, 2026
da2fbc3
Complete the errorbars and fill_between
certik Aug 15, 2026
3bfa2e3
Carry all the common colormaps
certik Aug 15, 2026
67c57eb
Plot against categories
certik Aug 15, 2026
0384765
Set exponents and indices with mathtext
certik Aug 15, 2026
438264a
Place and label the ticks as matplotlib does
certik Aug 15, 2026
9052a4b
Draw meshes with pcolormesh and pcolor
certik Aug 15, 2026
74c30c0
Span several cells with subplot2grid
certik Aug 15, 2026
7fbcbd3
Put dates on an axis
certik Aug 15, 2026
d96f0d9
Draw a field of arrows with quiver
certik Aug 15, 2026
b731be8
Label the contour lines with clabel
certik Aug 15, 2026
b9c265a
Place axes by hand, inside, and along an edge
certik Aug 15, 2026
c12c606
Draw plain shapes with the patches
certik Aug 15, 2026
3a0fc13
Plot in polar coordinates
certik Aug 15, 2026
a020998
Smooth an image with bilinear interpolation
certik Aug 15, 2026
f835656
Count points into bins with hist2d and hexbin
certik Aug 15, 2026
9842918
Show a matrix, a row of events, and broken bars
certik Aug 15, 2026
ebd4ff9
Trace the streamlines of a vector field
certik Aug 15, 2026
d6f9798
Put a table of text against the axes
certik Aug 15, 2026
6372978
Write the figure as encapsulated PostScript
certik Aug 15, 2026
846aa55
Save a sequence of figures as an animated GIF
certik Aug 15, 2026
6dc0208
Draw a 3D axes: lines, scatters and surfaces
certik Aug 15, 2026
94aa20c
Allocate the slice before assigning it
certik Aug 15, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ jobs:
run: pixi run compare-png
- name: Compare PDF output against matplotlib
run: pixi run compare-pdf
- name: Compare EPS output against matplotlib
run: pixi run compare-eps
- name: Compare GIF output against matplotlib
run: pixi run compare-gif
60 changes: 55 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![CI](https://github.com/certik/fplot/actions/workflows/ci.yml/badge.svg)](https://github.com/certik/fplot/actions/workflows/ci.yml)

Pure Fortran plotting library with a pylab-style API, writing SVG, PNG and PDF.
Pure Fortran plotting library with a pylab-style API, writing SVG, PNG, PDF and EPS.
No external graphics library: the PNG rasterizer and its font are part of fplot.

```fortran
Expand All @@ -13,7 +13,7 @@ call xlabel("x")
call ylabel("y")
call grid(.true.)
call legend()
call savefig("out.svg") ! or "out.png", "out.pdf"
call savefig("out.svg") ! or "out.png", "out.pdf", "out.eps"
call show() ! Jupyter (LFortran) or writes fplot_show.svg

! subplots
Expand Down Expand Up @@ -45,7 +45,7 @@ call suptitle("figure title")
- Optional `label=`, `lw=`, `color=`, `marker=`, `alpha=`
- Title, axis labels, grid, `xlim` / `ylim`, `clf` / `figure(figsize=, dpi=)`
- `savefig(file, transparent=, facecolor=)`; the extension picks the format,
one of `.svg`, `.png` or `.pdf`, and `dpi=` sizes the PNG raster
one of `.svg`, `.png`, `.pdf` or `.eps`, and `dpi=` sizes the PNG raster
- `axis("on"|"off"|"equal"|"scaled"|"tight"|"auto")` and `set_aspect`
- `set_xscale` / `set_yscale` with `"linear"`, `"log"` or `"symlog"`
- `tick_params(axis=, direction=, length=, labelsize=, rotation=)` and `spines`
Expand All @@ -55,11 +55,58 @@ call suptitle("figure title")
`set_fontsize(size=, title=, labels=, ticks=, legend=)` to set them globally
- `savefig(dpi=, bbox_inches="tight", pad_inches=)` to crop to the drawing
- Several live figures at once: `figure(num=)`, `gcf()`, `close(num=, all=)`
- `subplots(m, n, axs, sharex=, sharey=)` hands back axes handles, so
`call axs(1,2)%plot(x, y)` works alongside the stateful `subplot` style;
shared axes span the union of the group and drop their inner tick labels
- Subplots: `subplot(m, n, i)` and figure-level `suptitle`; per-axes state
(series, labels, grid, legend, scale, limits) with matplotlib's default
subplot spacing
- `subplots_adjust` and `tight_layout`
- `twinx` and `twiny` for a second y or x axis on the same plot
- Bars: `bar`/`barh` with `bottom=`/`left=` for stacks, `colors=` for a
color per bar, `edgecolor=`/`linewidth=`, and `bar_label(fmt=, padding=)`
- `add_axes` for an axes placed by hand, `inset_axes` for a small axes
inside another, and `secondary_xaxis`/`secondary_yaxis` for a second
scale along an edge
- `table` for a block of text below (or above) the axes
- `streamplot` for the streamlines of a vector field
- `add_frame` / `save_animation(file, fps=, loop=)` to write an animated GIF
- `matshow`, `eventplot` and `broken_barh`
- `hist2d` and `hexbin` for counting points into square or hexagonal bins
- `imshow(interpolation="bilinear")` to smooth an image instead of
showing it as blocks
- 3D axes: `plot3d`, `scatter3d` and `plot_surface`, with `view_init`,
`zlabel` and `zlim`, drawn with mplot3d's camera, panes and lighting
- Polar axes: `polar(theta, r)`, or `set_polar()` on an axes, with the
angular grid, the degree labels and the radial labels along 22.5°
- Patches: `add_rectangle`, `add_circle`, `add_ellipse` and `add_polygon`,
filled and outlined in data coordinates
- `clabel` to write the level into each contour line, breaking the line
at its straightest stretch to make room
- `quiver` for a field of arrows, sized as matplotlib sizes them
- Date axes: `date_num(y, m, d)` for the numbers and `xaxis_date()` to
have the ticks land on round dates and read as dates
- `subplot2grid`: panels that span several cells of a grid, so a wide
plot can sit over two narrow ones
- `pcolormesh` and `pcolor`: a grid of cells with edges of your own
choosing, which is what an unevenly sampled field needs
- matplotlib's tick locator and formatter: the same 1/2/2.5/5 steps, the
same number of ticks for the space available, and one decimal count
shared by the whole axis
- Mathtext: `$10^{-3}$`, `$x_i$`, `$E = mc^2$` in any label, laid out
once and drawn by every backend
- Categorical axes: `plot`, `bar` and `barh` take a list of names in place
of the numbers, and place them at 0, 1, 2, ... with the names as ticks
- 49 matplotlib colormaps, any of them reversed with a `_r` suffix, and
`imshow(norm="log")` for a logarithmic color scale
- `errorbar` with `xerr=` and asymmetric `yerr_lo=`/`yerr_hi=` arms
- `fill_between(where=)` to shade only where a condition holds
- `hist(bins=, bin_edges=, density=, cumulative=, histtype="step"/"stepfilled")`
- `axhspan`/`axvspan` shaded bands and `hlines`/`vlines` line runs
- `style_use("ggplot")` and friends (`seaborn`, `fivethirtyeight`,
`dark_background`, `grayscale`, `default`), or `rc(figsize=, dpi=,
fontsize=, linewidth=, grid=, facecolor=, axes_facecolor=, grid_color=,
text_color=, color_cycle=)` for one setting at a time
- Colors as CSS4/X11 names, `tab:` names, `#rgb`, `#rrggbb`, `#rrggbbaa`,
single letters, `C0`-`C9`, or a greyscale fraction such as `"0.5"`
- SVG defaults aligned with matplotlib (6.4×4.8 in, tab10 colors, subplot margins)
Expand All @@ -86,13 +133,16 @@ pixi run test-lfortran
pixi run compare # SVG, structurally
pixi run compare-png # PNG, pixel by pixel
pixi run compare-pdf # PDF, rasterized by pdftoppm
pixi run compare-eps # EPS, rasterized by ghostscript
pixi run compare-gif # GIF, frame by frame
```

The SVG comparison is structural because a viewer, not fplot, decides what an
SVG looks like. PNG and PDF are compared as pixels, since there fplot decides.
SVG looks like. PNG, PDF and EPS are compared as pixels, since there fplot
decides.

CI (Linux) runs `pixi run test-flang` and `pixi run test-lfortran`, then all
three comparisons.
five comparisons.

## Layout

Expand Down
25 changes: 25 additions & 0 deletions pixi.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ demo-lfortran = "bash scripts/build_lfortran.sh && ./build/lfortran/demo"

mpl-refs = "python tests/gen_mpl_refs.py"

# The three comparisons share their setup, so it is expressed once as a
# dependency rather than repeated in each command and run three times.
# The five comparisons share their setup, so it is expressed once as a
# dependency rather than repeated in each command and run five times.
[tasks.compare]
cmd = "python tests/compare_svgs.py"
depends-on = ["mpl-refs", "test-flang"]
Expand All @@ -31,6 +31,14 @@ depends-on = ["mpl-refs", "test-flang"]
cmd = "python tests/compare_pdfs.py"
depends-on = ["mpl-refs", "test-flang"]

[tasks.compare-eps]
cmd = "python tests/compare_eps.py"
depends-on = ["mpl-refs", "test-flang"]

[tasks.compare-gif]
cmd = "python tests/compare_gif.py"
depends-on = ["mpl-refs", "test-flang"]

[dependencies]
python = ">=3.14.6,<3.15"
matplotlib = ">=3.11.1,<4"
Expand All @@ -40,6 +48,8 @@ pillow = ">=12.3.0,<13"
# pdftoppm, for rasterizing PDFs in tests/compare_pdfs.py
poppler = "*"
lfortran = ">=0.64.0,<0.65"
# gs, for rasterizing EPS in tests/compare_eps.py
ghostscript = ">=10.4.0,<11"

[target.linux-64.dependencies]
flang_linux-64 = ">=22,<23"
9 changes: 7 additions & 2 deletions scripts/build_flang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,23 @@ $FLANG -c "$ROOT/src/fplot_png.f90"
$FLANG -c "$ROOT/src/fplot_backend_svg.f90"
$FLANG -c "$ROOT/src/fplot_glyphs.f90"
$FLANG -c "$ROOT/src/fplot_raster.f90"
$FLANG -c "$ROOT/src/fplot_mathtext.f90"
$FLANG -c "$ROOT/src/fplot_dates.f90"
$FLANG -c "$ROOT/src/fplot_backend_pdf.f90"
$FLANG -c "$ROOT/src/fplot_backend_eps.f90"
$FLANG -c "$ROOT/src/fplot_backend_png.f90"
$FLANG -c "$ROOT/src/fplot_gif.f90"
$FLANG -c "$ROOT/src/fplot_proj3d.f90"
$FLANG -c "$ROOT/src/fplot.f90"

# Test program
$FLANG -o "$BUILD/test_plots" \
"$ROOT/tests/test_plots.f90" \
fplot_colors.o fplot_style.o fplot_render.o fplot_scale.o fplot_cmap.o fplot_ticks.o fplot_contour.o fplot_svg.o fplot_backend_svg.o fplot_backend_pdf.o fplot_glyphs.o fplot_png.o fplot_raster.o fplot_backend_png.o fplot.o
fplot_colors.o fplot_style.o fplot_render.o fplot_scale.o fplot_cmap.o fplot_ticks.o fplot_contour.o fplot_svg.o fplot_backend_svg.o fplot_backend_pdf.o fplot_backend_eps.o fplot_glyphs.o fplot_png.o fplot_raster.o fplot_backend_png.o fplot_gif.o fplot_proj3d.o fplot_mathtext.o fplot_dates.o fplot.o

# Demo
$FLANG -o "$BUILD/demo" \
"$ROOT/examples/demo.f90" \
fplot_colors.o fplot_style.o fplot_render.o fplot_scale.o fplot_cmap.o fplot_ticks.o fplot_contour.o fplot_svg.o fplot_backend_svg.o fplot_backend_pdf.o fplot_glyphs.o fplot_png.o fplot_raster.o fplot_backend_png.o fplot.o
fplot_colors.o fplot_style.o fplot_render.o fplot_scale.o fplot_cmap.o fplot_ticks.o fplot_contour.o fplot_svg.o fplot_backend_svg.o fplot_backend_pdf.o fplot_backend_eps.o fplot_glyphs.o fplot_png.o fplot_raster.o fplot_backend_png.o fplot_gif.o fplot_proj3d.o fplot_mathtext.o fplot_dates.o fplot.o

echo "Built: $BUILD/test_plots $BUILD/demo"
9 changes: 7 additions & 2 deletions scripts/build_lfortran.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,22 @@ $LFORTRAN -c "$ROOT/src/fplot_png.f90"
$LFORTRAN -c "$ROOT/src/fplot_backend_svg.f90"
$LFORTRAN -c "$ROOT/src/fplot_glyphs.f90"
$LFORTRAN -c "$ROOT/src/fplot_raster.f90"
$LFORTRAN -c "$ROOT/src/fplot_mathtext.f90"
$LFORTRAN -c "$ROOT/src/fplot_dates.f90"
$LFORTRAN -c "$ROOT/src/fplot_backend_pdf.f90"
$LFORTRAN -c "$ROOT/src/fplot_backend_eps.f90"
$LFORTRAN -c "$ROOT/src/fplot_backend_png.f90"
$LFORTRAN -c "$ROOT/src/fplot_gif.f90"
$LFORTRAN -c "$ROOT/src/fplot_proj3d.f90"
$LFORTRAN -c "$ROOT/src/fplot.f90"

$LFORTRAN -o "$BUILD/test_plots" \
"$ROOT/tests/test_plots.f90" \
fplot_colors.o fplot_style.o fplot_render.o fplot_scale.o fplot_cmap.o fplot_ticks.o fplot_contour.o fplot_svg.o fplot_backend_svg.o fplot_backend_pdf.o fplot_glyphs.o fplot_png.o fplot_raster.o fplot_backend_png.o fplot.o
fplot_colors.o fplot_style.o fplot_render.o fplot_scale.o fplot_cmap.o fplot_ticks.o fplot_contour.o fplot_svg.o fplot_backend_svg.o fplot_backend_pdf.o fplot_backend_eps.o fplot_glyphs.o fplot_png.o fplot_raster.o fplot_backend_png.o fplot_gif.o fplot_proj3d.o fplot_mathtext.o fplot_dates.o fplot.o

$LFORTRAN -o "$BUILD/demo" \
"$ROOT/examples/demo.f90" \
fplot_colors.o fplot_style.o fplot_render.o fplot_scale.o fplot_cmap.o fplot_ticks.o fplot_contour.o fplot_svg.o fplot_backend_svg.o fplot_backend_pdf.o fplot_glyphs.o fplot_png.o fplot_raster.o fplot_backend_png.o fplot.o
fplot_colors.o fplot_style.o fplot_render.o fplot_scale.o fplot_cmap.o fplot_ticks.o fplot_contour.o fplot_svg.o fplot_backend_svg.o fplot_backend_pdf.o fplot_backend_eps.o fplot_glyphs.o fplot_png.o fplot_raster.o fplot_backend_png.o fplot_gif.o fplot_proj3d.o fplot_mathtext.o fplot_dates.o fplot.o

echo "Built: $BUILD/test_plots $BUILD/demo"
echo "Jupyter: use display_data('image/svg+xml', render_svg()) with lfortran_display"
Loading
Loading