diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 9ce5521..27800a9 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -29,3 +29,7 @@ jobs:
run: pixi run test-lfortran
- name: Compare against matplotlib references
run: pixi run compare
+ - name: Compare PNG output against matplotlib
+ run: pixi run compare-png
+ - name: Compare PDF output against matplotlib
+ run: pixi run compare-pdf
diff --git a/README.md b/README.md
index 30a73c6..00ee5ab 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,8 @@
[](https://github.com/certik/fplot/actions/workflows/ci.yml)
-Pure Fortran plotting library that emits SVG text, with a pylab-style API.
+Pure Fortran plotting library with a pylab-style API, writing SVG, PNG and PDF.
+No external graphics library: the PNG rasterizer and its font are part of fplot.
```fortran
use fplot
@@ -12,7 +13,7 @@ call xlabel("x")
call ylabel("y")
call grid(.true.)
call legend()
-call savefig("out.svg") ! file backend
+call savefig("out.svg") ! or "out.png", "out.pdf"
call show() ! Jupyter (LFortran) or writes fplot_show.svg
! subplots
@@ -43,7 +44,8 @@ call suptitle("figure title")
markers `o x . s ^ v < > * + D`
- Optional `label=`, `lw=`, `color=`, `marker=`, `alpha=`
- Title, axis labels, grid, `xlim` / `ylim`, `clf` / `figure(figsize=, dpi=)`
-- `savefig(file, transparent=, facecolor=)`
+- `savefig(file, transparent=, facecolor=)`; the extension picks the format,
+ one of `.svg`, `.png` or `.pdf`, 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`
@@ -80,19 +82,24 @@ pixi run demo-flang
pixi run build-lfortran
pixi run test-lfortran
-# Compare against matplotlib reference SVGs
-pixi run compare
+# Compare against matplotlib references
+pixi run compare # SVG, structurally
+pixi run compare-png # PNG, pixel by pixel
+pixi run compare-pdf # PDF, rasterized by pdftoppm
```
-CI (Linux) runs `pixi run test-flang`, `pixi run test-lfortran` and
-`pixi run compare`.
+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.
+
+CI (Linux) runs `pixi run test-flang` and `pixi run test-lfortran`, then all
+three comparisons.
## Layout
```
src/ library modules
examples/ demo.f90
-tests/ Fortran test plots, matplotlib refs, compare script
+tests/ Fortran test plots, matplotlib refs, compare scripts
scripts/ build_flang.sh, build_lfortran.sh
```
diff --git a/pixi.lock b/pixi.lock
index 03d0cd1..cfd168b 100644
--- a/pixi.lock
+++ b/pixi.lock
@@ -24,6 +24,7 @@ environments:
- conda: https://conda.anaconda.org/conda-forge/linux-64/brotli-1.2.0-h505cf86_3.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/brotli-bin-1.2.0-h9908984_3.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/bzip2-1.0.8-hda65f42_10.conda
+ - conda: https://conda.anaconda.org/conda-forge/linux-64/c-ares-1.34.8-h280c20c_1.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/cairo-1.18.4-he90730b_1.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/cffi-2.1.1-py314h77c0f9c_1.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/clang-22-22.1.8-default_hd70ba2e_6.conda
@@ -69,11 +70,13 @@ environments:
- conda: https://conda.anaconda.org/conda-forge/linux-64/libclang13-22.1.8-default_hd70ba2e_6.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/libcompiler-rt-22.1.8-hb700be7_1.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/libcups-2.3.3-h7a8fb5f_6.conda
+ - conda: https://conda.anaconda.org/conda-forge/linux-64/libcurl-8.21.0-heca4667_4.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/libdeflate-1.25-hd45a770_1.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/libdrm-2.4.129-h7cc23a3_0.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/libedit-3.1.20250104-pl5321h373387f_1.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/libegl-1.7.0-ha4b6fd6_3.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/libegl-devel-1.7.0-ha4b6fd6_3.conda
+ - conda: https://conda.anaconda.org/conda-forge/linux-64/libev-4.33-h280c20c_3.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/libexpat-2.8.1-hecca717_1.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/libffi-3.7.0-h3435931_0.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/libflang-rt-22.1.8-ha4b6fd6_0.conda
@@ -98,15 +101,18 @@ environments:
- conda: https://conda.anaconda.org/conda-forge/linux-64/libllvm22-22.1.8-hf7376ad_1.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/liblzma-5.8.3-hb03c661_1.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/libmpdec-4.0.0-hb03c661_2.conda
+ - conda: https://conda.anaconda.org/conda-forge/linux-64/libnghttp2-1.68.1-h877daf1_0.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/libntlm-1.8-hb9d3cd8_0.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/libopenblas-0.3.34-pthreads_h94d23a6_0.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/libopengl-1.7.0-ha4b6fd6_3.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/libpciaccess-0.19-hb03c661_1.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/libpng-1.6.58-h922cc85_1.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/libpq-18.6-h9d76c99_0.conda
+ - conda: https://conda.anaconda.org/conda-forge/linux-64/libpsl-0.23.1-hf670292_0.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/libraqm-0.11.0-h6406941_0.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/libsodium-1.0.22-h280c20c_1.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/libsqlite-3.53.4-hf4e2dac_0.conda
+ - conda: https://conda.anaconda.org/conda-forge/linux-64/libssh2-1.11.1-h6154650_1.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/libstdcxx-16.1.0-h934c35e_1.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/libstdcxx-ng-16.1.0-hdf11a46_1.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/libtiff-4.7.2-h9d88235_0.conda
@@ -128,6 +134,8 @@ environments:
- conda: https://conda.anaconda.org/conda-forge/linux-64/matplotlib-3.11.1-py314h815e797_2.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/matplotlib-base-3.11.1-py314h9a9c090_2.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/ncurses-6.6-hdb14827_1.conda
+ - conda: https://conda.anaconda.org/conda-forge/linux-64/nspr-4.40-h29cc59b_0.conda
+ - conda: https://conda.anaconda.org/conda-forge/linux-64/nss-3.118-h445c969_0.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/numpy-2.5.2-py314h2b28147_0.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/openjpeg-2.5.4-h55fea9a_0.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/openldap-2.6.13-hbde042b_0.conda
@@ -135,6 +143,7 @@ environments:
- conda: https://conda.anaconda.org/conda-forge/linux-64/pcre2-10.47-haa7fec5_0.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/pillow-12.3.0-py314h8ec4b1a_0.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/pixman-0.46.4-h54a6638_3.conda
+ - conda: https://conda.anaconda.org/conda-forge/linux-64/poppler-26.07.0-he594abd_3.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/pthread-stubs-0.4-hb03c661_1003.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/pyside6-6.11.1-py314h3987850_1.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/python-3.14.6-h242f9ac_102_cp314.conda
@@ -167,6 +176,7 @@ environments:
- conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-libxi-1.8.3-hb03c661_0.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-libxrandr-1.5.5-hb03c661_0.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-libxrender-0.9.12-hb9d3cd8_0.conda
+ - conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-libxscrnsaver-1.2.4-hb9d3cd8_0.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-libxtst-1.2.5-hb9d3cd8_3.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-libxxf86vm-1.1.7-hb03c661_0.conda
- conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-xorgproto-2025.1-h280c20c_1.conda
@@ -195,6 +205,7 @@ environments:
- conda: https://conda.anaconda.org/conda-forge/noarch/munkres-1.1.4-pyhd8ed1ab_1.conda
- conda: https://conda.anaconda.org/conda-forge/noarch/nlohmann_json-abi-3.12.0-h0f90c79_2.conda
- conda: https://conda.anaconda.org/conda-forge/noarch/packaging-26.3-pyhc364b38_0.conda
+ - conda: https://conda.anaconda.org/conda-forge/noarch/poppler-data-0.4.12-hd8ed1ab_0.conda
- conda: https://conda.anaconda.org/conda-forge/noarch/pycparser-3.0-pyhcf101f3_0.conda
- conda: https://conda.anaconda.org/conda-forge/noarch/pyparsing-3.3.2-pyhcf101f3_0.conda
- conda: https://conda.anaconda.org/conda-forge/noarch/python-dateutil-2.9.0.post0-pyhe01879c_2.conda
@@ -221,6 +232,7 @@ environments:
- conda: https://conda.anaconda.org/conda-forge/noarch/munkres-1.1.4-pyhd8ed1ab_1.conda
- conda: https://conda.anaconda.org/conda-forge/noarch/nlohmann_json-abi-3.12.0-h0f90c79_2.conda
- conda: https://conda.anaconda.org/conda-forge/noarch/packaging-26.3-pyhc364b38_0.conda
+ - conda: https://conda.anaconda.org/conda-forge/noarch/poppler-data-0.4.12-hd8ed1ab_0.conda
- conda: https://conda.anaconda.org/conda-forge/noarch/pycparser-3.0-pyhcf101f3_0.conda
- conda: https://conda.anaconda.org/conda-forge/noarch/pyparsing-3.3.2-pyhcf101f3_0.conda
- conda: https://conda.anaconda.org/conda-forge/noarch/python-dateutil-2.9.0.post0-pyhe01879c_2.conda
@@ -233,6 +245,7 @@ environments:
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/brotli-1.2.0-h7d5ae5b_1.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/brotli-bin-1.2.0-hc919400_1.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/bzip2-1.0.8-h4e30115_10.conda
+ - conda: https://conda.anaconda.org/conda-forge/osx-arm64/c-ares-1.34.8-h1a92334_1.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/cairo-1.18.4-he0f2337_1.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/cffi-2.1.1-py314h7bede21_0.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/contourpy-1.3.3-py314hf8a3a22_4.conda
@@ -251,9 +264,11 @@ environments:
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libbrotlidec-1.2.0-hc919400_1.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libbrotlienc-1.2.0-hc919400_1.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libcblas-3.11.0-9_hb0561ab_openblas.conda
+ - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libcurl-8.21.0-hf618e03_4.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libcxx-22.1.8-h55c6f16_0.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libdeflate-1.25-he7e0567_1.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libedit-3.1.20250104-pl5321h26f1114_1.conda
+ - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libev-4.33-h1a92334_3.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libexpat-2.8.1-hf6b4638_1.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libffi-3.5.2-hcf2aa1b_0.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libfreetype-2.14.3-hce30654_1.conda
@@ -269,11 +284,14 @@ environments:
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/liblapack-3.11.0-9_hd9741b5_openblas.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/liblzma-5.8.3-h8088a28_0.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libmpdec-4.0.0-h84a0fba_1.conda
+ - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libnghttp2-1.68.1-h8f3e76b_0.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libopenblas-0.3.34-openmp_he657e61_0.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libpng-1.6.58-h132b30e_0.conda
+ - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libpsl-0.23.1-h7a62e17_0.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libraqm-0.11.0-h45af499_0.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libsodium-1.0.22-h1a92334_1.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libsqlite-3.53.4-h1ae2325_0.conda
+ - conda: https://conda.anaconda.org/conda-forge/osx-arm64/libssh2-1.11.1-hbf2880b_1.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libtiff-4.7.2-h282da08_0.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libwebp-base-1.6.0-h202fb40_1.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libxcb-1.17.0-hdb1d25a_0.conda
@@ -282,12 +300,15 @@ environments:
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/matplotlib-3.11.1-py314h314fc0d_2.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/matplotlib-base-3.11.1-py314h27b0870_2.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/ncurses-6.6-h1d4f5a5_0.conda
+ - conda: https://conda.anaconda.org/conda-forge/osx-arm64/nspr-4.40-hdcbdcf5_0.conda
+ - conda: https://conda.anaconda.org/conda-forge/osx-arm64/nss-3.118-h1c710a3_0.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/numpy-2.5.1-py314hb79c6fa_0.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/openjpeg-2.5.4-hd9e9057_0.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/openssl-3.6.3-hd24854e_1.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/pcre2-10.47-h30297fc_0.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/pillow-12.3.0-py314hab283cf_0.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/pixman-0.46.4-h784d473_3.conda
+ - conda: https://conda.anaconda.org/conda-forge/osx-arm64/poppler-26.07.0-h4cfec15_3.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/pthread-stubs-0.4-h84a0fba_1003.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/python-3.14.6-h156bc91_101_cp314.conda
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/qhull-2020.2-h420ef59_5.conda
@@ -398,6 +419,21 @@ packages:
- bzip2 >=1.0.8,<2.0a0
size: 257808
timestamp: 1785906269155
+- conda: https://conda.anaconda.org/conda-forge/linux-64/c-ares-1.34.8-h280c20c_1.conda
+ sha256: 5139b6afbfaca91c47104ba9a6a40f81211e1c9200e96b73ce3a56f0ca1902f4
+ md5: 2cef891b791040aab83e218c7d137679
+ depends:
+ - __glibc >=2.17,<3.0.a0
+ - libgcc >=14
+ constrains:
+ - c-ares-static <0a0
+ license: MIT
+ license_family: MIT
+ run_exports:
+ weak:
+ - c-ares >=1.34.8,<2.0a0
+ size: 226755
+ timestamp: 1786116641939
- conda: https://conda.anaconda.org/conda-forge/linux-64/cairo-1.18.4-he90730b_1.conda
sha256: 06525fa0c4e4f56e771a3b986d0fdf0f0fc5a3270830ee47e127a5105bde1b9a
md5: bb6c4808bfa69d6f7f6b07e5846ced37
@@ -1146,6 +1182,26 @@ packages:
- libcups >=2.3.3,<2.4.0a0
size: 4518030
timestamp: 1770902209173
+- conda: https://conda.anaconda.org/conda-forge/linux-64/libcurl-8.21.0-heca4667_4.conda
+ sha256: aff8ef75636d0825ce34911e0bef2f26816e7afd090a9dcb4b9bacab75cbf584
+ md5: 3f2fd5617cfacac49c85f6dc63842ea1
+ depends:
+ - __glibc >=2.17,<3.0.a0
+ - krb5 >=1.22.2,<1.23.0a0
+ - libgcc >=14
+ - libnghttp2 >=1.68.1,<2.0a0
+ - libpsl >=0.23.0,<0.24.0a0
+ - libssh2 >=1.11.1,<2.0a0
+ - libzlib >=1.3.2,<2.0a0
+ - openssl >=3.5.7,<4.0a0
+ - zstd >=1.5.7,<1.6.0a0
+ license: curl
+ license_family: MIT
+ run_exports:
+ weak:
+ - libcurl >=8.21.0,<9.0a0
+ size: 480565
+ timestamp: 1785500108494
- conda: https://conda.anaconda.org/conda-forge/linux-64/libdeflate-1.25-hd45a770_1.conda
sha256: 82e134c8a08b1eed9a2ed8ab578b89aa1730dcde3dea8dd87645ed0637878e54
md5: 40f9b31aa9cf007789867df0decd0492
@@ -1212,6 +1268,19 @@ packages:
- libegl >=1.7.0,<2.0a0
size: 31718
timestamp: 1779728222280
+- conda: https://conda.anaconda.org/conda-forge/linux-64/libev-4.33-h280c20c_3.conda
+ sha256: e4418f68d01a6307c4431b585c71b584f40189877364e542ee87deb777f5e85b
+ md5: 7bc31538d6e3fb349e897353969237ec
+ depends:
+ - libgcc >=14
+ - __glibc >=2.17,<3.0.a0
+ license: BSD-2-Clause OR GPL-2.0-or-later
+ license_family: GPL
+ run_exports:
+ weak:
+ - libev >=4.33,<4.34.0a0
+ size: 43220
+ timestamp: 1785917328200
- conda: https://conda.anaconda.org/conda-forge/linux-64/libexpat-2.8.1-hecca717_1.conda
sha256: 16feffd9ddbbe5b718515d38ee376c685ba95491cd901244e24671d20b952a77
md5: b24d3c612f71e7aa74158d92106318b2
@@ -1541,6 +1610,25 @@ packages:
run_exports: {}
size: 92759
timestamp: 1786650399772
+- conda: https://conda.anaconda.org/conda-forge/linux-64/libnghttp2-1.68.1-h877daf1_0.conda
+ sha256: 663444d77a42f2265f54fb8b48c5450bfff4388d9c0f8253dd7855f0d993153f
+ md5: 2a45e7f8af083626f009645a6481f12d
+ depends:
+ - __glibc >=2.17,<3.0.a0
+ - c-ares >=1.34.6,<2.0a0
+ - libev >=4.33,<4.34.0a0
+ - libev >=4.33,<5.0a0
+ - libgcc >=14
+ - libstdcxx >=14
+ - libzlib >=1.3.1,<2.0a0
+ - openssl >=3.5.5,<4.0a0
+ license: MIT
+ license_family: MIT
+ run_exports:
+ weak:
+ - libnghttp2 >=1.68.1,<2.0a0
+ size: 663344
+ timestamp: 1773854035739
- conda: https://conda.anaconda.org/conda-forge/linux-64/libntlm-1.8-hb9d3cd8_0.conda
sha256: 3b3f19ced060013c2dd99d9d46403be6d319d4601814c772a3472fe2955612b0
md5: 7c7927b404672409d9917d49bff5f2d6
@@ -1622,6 +1710,21 @@ packages:
- libpq >=18.6,<19.0a0
size: 2719680
timestamp: 1786641133110
+- conda: https://conda.anaconda.org/conda-forge/linux-64/libpsl-0.23.1-hf670292_0.conda
+ sha256: 2e6405feb59e3f40a5a4641dfa73afda158046893aa73d478e23415e18997ece
+ md5: c8217f5bdd5b018087bdea081912cda5
+ depends:
+ - libgcc >=14
+ - libstdcxx >=14
+ - __glibc >=2.17,<3.0.a0
+ - icu >=78.3,<79.0a0
+ license: MIT
+ license_family: MIT
+ run_exports:
+ weak:
+ - libpsl >=0.23.1,<0.24.0a0
+ size: 72505
+ timestamp: 1786443494718
- conda: https://conda.anaconda.org/conda-forge/linux-64/libraqm-0.11.0-h6406941_0.conda
sha256: ab3ccb9fd5816f76b18ee8974d359cd2605ca87d8ddef55369dc461b9986f95c
md5: 3ac89a48d224409739dbf6200e524373
@@ -1665,6 +1768,21 @@ packages:
- libsqlite >=3.53.4,<4.0a0
size: 964200
timestamp: 1785016112246
+- conda: https://conda.anaconda.org/conda-forge/linux-64/libssh2-1.11.1-h6154650_1.conda
+ sha256: 7e463000fa1cba3f3a6597b776f6ab301d425a96e3bc20d0d9d76a3b9f237aa3
+ md5: 5c526561e1d2a2e071941174eae84557
+ depends:
+ - __glibc >=2.17,<3.0.a0
+ - libgcc >=14
+ - libzlib >=1.3.2,<2.0a0
+ - openssl >=3.5.7,<4.0a0
+ license: BSD-3-Clause
+ license_family: BSD
+ run_exports:
+ weak:
+ - libssh2 >=1.11.1,<2.0a0
+ size: 306045
+ timestamp: 1786713107897
- conda: https://conda.anaconda.org/conda-forge/linux-64/libstdcxx-16.1.0-h934c35e_1.conda
sha256: 79721dd08aeb0ab9e773f1f9ef41cf4e6c17477e3d72319147619045bce05a09
md5: aed6cf89adc1e9b846e4367ac538e434
@@ -2010,6 +2128,37 @@ packages:
- ncurses >=6.6,<7.0a0
size: 911196
timestamp: 1786355078102
+- conda: https://conda.anaconda.org/conda-forge/linux-64/nspr-4.40-h29cc59b_0.conda
+ sha256: 7cf473259ef9945ce19ecc898a2dd146cd32dc86099d87b86f79c5e5b0ef55f0
+ md5: 4ebda462e16da6e6164cb82b9d58fcea
+ depends:
+ - __glibc >=2.17,<3.0.a0
+ - libgcc >=14
+ - libstdcxx >=14
+ license: MPL-2.0
+ license_family: MOZILLA
+ run_exports:
+ weak:
+ - nspr >=4.40,<5.0a0
+ size: 231356
+ timestamp: 1786154777346
+- conda: https://conda.anaconda.org/conda-forge/linux-64/nss-3.118-h445c969_0.conda
+ sha256: 44dd98ffeac859d84a6dcba79a2096193a42fc10b29b28a5115687a680dd6aea
+ md5: 567fbeed956c200c1db5782a424e58ee
+ depends:
+ - __glibc >=2.17,<3.0.a0
+ - libgcc >=14
+ - libsqlite >=3.51.0,<4.0a0
+ - libstdcxx >=14
+ - libzlib >=1.3.1,<2.0a0
+ - nspr >=4.38,<5.0a0
+ license: MPL-2.0
+ license_family: MOZILLA
+ run_exports:
+ weak:
+ - nss >=3.118,<4.0a0
+ size: 2057773
+ timestamp: 1763485556350
- conda: https://conda.anaconda.org/conda-forge/linux-64/numpy-2.5.2-py314h2b28147_0.conda
sha256: 124b753583ea9c157301fe78de3e88aa5fa8806bd2da8abaa8808065d1b93d51
md5: d77631addad93399a90157d2c597e7f3
@@ -2130,6 +2279,41 @@ packages:
- pixman >=0.46.4,<1.0a0
size: 376704
timestamp: 1786106621354
+- conda: https://conda.anaconda.org/conda-forge/linux-64/poppler-26.07.0-he594abd_3.conda
+ sha256: 646869d659de20b98caf6e249b468d1a13b4593f5d83ce7f269fc75aed18faf0
+ md5: 386b8320e1f218cb1a1d75edc7ac3599
+ depends:
+ - __glibc >=2.17,<3.0.a0
+ - cairo >=1.18.4,<2.0a0
+ - fontconfig >=2.18.1,<3.0a0
+ - fonts-conda-ecosystem
+ - lcms2 >=2.19.1,<3.0a0
+ - libcurl >=8.21.0,<9.0a0
+ - libegl >=1.7.0,<2.0a0
+ - libfreetype >=2.14.3
+ - libfreetype6 >=2.14.3
+ - libgcc >=14
+ - libgl >=1.7.0,<2.0a0
+ - libglib >=2.88.2,<3.0a0
+ - libiconv >=1.18,<2.0a0
+ - libjpeg-turbo >=3.1.4.1,<4.0a0
+ - libpng >=1.6.58,<1.7.0a0
+ - libstdcxx >=14
+ - libtiff >=4.7.2,<4.8.0a0
+ - libzlib >=1.3.2,<2.0a0
+ - nspr >=4.38,<5.0a0
+ - nss >=3.118,<4.0a0
+ - openjpeg >=2.5.4,<3.0a0
+ - poppler-data
+ - xorg-libxscrnsaver >=1.2.4,<2.0a0
+ - xorg-libxtst >=1.2.5,<2.0a0
+ license: GPL-2.0-or-later
+ license_family: GPL
+ run_exports:
+ weak:
+ - poppler >=26.7.0,<26.8.0a0
+ size: 2113458
+ timestamp: 1783343328643
- conda: https://conda.anaconda.org/conda-forge/linux-64/pthread-stubs-0.4-hb03c661_1003.conda
sha256: afc3b27b2cbb0487c1d0e963f96e71181ecfb623a24fb393bb19ff974a6382a1
md5: df2c27f36bdb0dde779f55b5df76a352
@@ -2677,6 +2861,21 @@ packages:
- xorg-libxrender >=0.9.12,<0.10.0a0
size: 33005
timestamp: 1734229037766
+- conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-libxscrnsaver-1.2.4-hb9d3cd8_0.conda
+ sha256: 58e8fc1687534124832d22e102f098b5401173212ac69eb9fd96b16a3e2c8cb2
+ md5: 303f7a0e9e0cd7d250bb6b952cecda90
+ depends:
+ - __glibc >=2.17,<3.0.a0
+ - libgcc >=13
+ - xorg-libx11 >=1.8.10,<2.0a0
+ - xorg-libxext >=1.3.6,<2.0a0
+ license: MIT
+ license_family: MIT
+ run_exports:
+ weak:
+ - xorg-libxscrnsaver >=1.2.4,<2.0a0
+ size: 14412
+ timestamp: 1727899730073
- conda: https://conda.anaconda.org/conda-forge/linux-64/xorg-libxtst-1.2.5-hb9d3cd8_3.conda
sha256: 752fdaac5d58ed863bbf685bb6f98092fe1a488ea8ebb7ed7b606ccfce08637a
md5: 7bbe9a0cc0df0ac5f5a8ad6d6a11af2f
@@ -2997,6 +3196,14 @@ packages:
run_exports: {}
size: 116363
timestamp: 1785888127370
+- conda: https://conda.anaconda.org/conda-forge/noarch/poppler-data-0.4.12-hd8ed1ab_0.conda
+ sha256: 2f227e17b3c0346112815faa605502b66c1c4511a856127f2899abf15a98a2cf
+ md5: d8d7293c5b37f39b2ac32940621c6592
+ license: BSD-3-Clause AND (GPL-2.0-only OR GPL-3.0-only)
+ license_family: OTHER
+ run_exports: {}
+ size: 2348171
+ timestamp: 1675353652214
- conda: https://conda.anaconda.org/conda-forge/noarch/pycparser-3.0-pyhcf101f3_0.conda
sha256: e27e0473fc6723311a0bd48b89b616fa1b996a2f7a2b555338cbbcfb9c640568
md5: 9c5491066224083c41b6d5635ed7107b
@@ -3150,6 +3357,20 @@ packages:
- bzip2 >=1.0.8,<2.0a0
size: 124965
timestamp: 1785906749812
+- conda: https://conda.anaconda.org/conda-forge/osx-arm64/c-ares-1.34.8-h1a92334_1.conda
+ sha256: 104b41473845649101ba8ebf8221c7431256465d34ce380b10e9a90558ed33ac
+ md5: 7d9390a4d4b43f91652823d870f68065
+ depends:
+ - __osx >=11.0
+ constrains:
+ - c-ares-static <0a0
+ license: MIT
+ license_family: MIT
+ run_exports:
+ weak:
+ - c-ares >=1.34.8,<2.0a0
+ size: 197274
+ timestamp: 1786116660078
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/cairo-1.18.4-he0f2337_1.conda
sha256: cde9b79ee206fe3ba6ca2dc5906593fb7a1350515f85b2a1135a4ce8ec1539e3
md5: 36200ecfbbfbcb82063c87725434161f
@@ -3412,6 +3633,25 @@ packages:
- libcblas >=3.11.0,<4.0a0
size: 18110
timestamp: 1786058893756
+- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libcurl-8.21.0-hf618e03_4.conda
+ sha256: d25be36712d7f854a5f93513b9fbf1b0ee3219975b7fef4a3ee071b021b10167
+ md5: 66cf9c5003ee81ecdb0dc9f9df17bbe5
+ depends:
+ - __osx >=11.0
+ - krb5 >=1.22.2,<1.23.0a0
+ - libnghttp2 >=1.68.1,<2.0a0
+ - libpsl >=0.23.0,<0.24.0a0
+ - libssh2 >=1.11.1,<2.0a0
+ - libzlib >=1.3.2,<2.0a0
+ - openssl >=3.5.7,<4.0a0
+ - zstd >=1.5.7,<1.6.0a0
+ license: curl
+ license_family: MIT
+ run_exports:
+ weak:
+ - libcurl >=8.21.0,<9.0a0
+ size: 411491
+ timestamp: 1785500129743
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libcxx-22.1.8-h55c6f16_0.conda
sha256: a2e7abab5add9750fab064c024394de48e49f97631c605ad5db5c8ac3fc769ef
md5: 89f76a2a21a3ec3ec983b5eb237c4113
@@ -3447,6 +3687,18 @@ packages:
- libedit >=3.1.20250104,<3.2.0a0
size: 107742
timestamp: 1786616721640
+- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libev-4.33-h1a92334_3.conda
+ sha256: c0100064506ae8abb432c5a506d474f10af2cf48c33d62bc221fb28b6d6ff6ac
+ md5: 19e86c8a6a47e92bb2e70ca12e758c5c
+ depends:
+ - __osx >=11.0
+ license: BSD-2-Clause OR GPL-2.0-or-later
+ license_family: GPL
+ run_exports:
+ weak:
+ - libev >=4.33,<4.34.0a0
+ size: 39991
+ timestamp: 1785917376956
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libexpat-2.8.1-hf6b4638_1.conda
sha256: 5af74261101e3c777399c6294b2b5d290e508153268eb2e9ff99c4d69834612f
md5: a915151d5d3c5bf039f5ccc8402a436f
@@ -3642,6 +3894,24 @@ packages:
run_exports: {}
size: 73690
timestamp: 1769482560514
+- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libnghttp2-1.68.1-h8f3e76b_0.conda
+ sha256: 2bc7bc3978066f2c274ebcbf711850cc9ab92e023e433b9631958a098d11e10a
+ md5: 6ea18834adbc3b33df9bd9fb45eaf95b
+ depends:
+ - __osx >=11.0
+ - c-ares >=1.34.6,<2.0a0
+ - libcxx >=19
+ - libev >=4.33,<4.34.0a0
+ - libev >=4.33,<5.0a0
+ - libzlib >=1.3.1,<2.0a0
+ - openssl >=3.5.5,<4.0a0
+ license: MIT
+ license_family: MIT
+ run_exports:
+ weak:
+ - libnghttp2 >=1.68.1,<2.0a0
+ size: 576526
+ timestamp: 1773854624224
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libopenblas-0.3.34-openmp_he657e61_0.conda
sha256: bcf1967f12f1b1cc769dcc77b255fb1b27aaceb2f185450e9596d137bc6ede76
md5: 89d28fb841cf16211318524fa985e384
@@ -3671,6 +3941,20 @@ packages:
- libpng >=1.6.58,<1.7.0a0
size: 289546
timestamp: 1776315246750
+- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libpsl-0.23.1-h7a62e17_0.conda
+ sha256: 0140cb0d059ac531e476b85a543668b69b7dffec16f0d26269ab6c9b70546921
+ md5: 75a4cdf128d016141db61732ea462276
+ depends:
+ - __osx >=11.0
+ - libcxx >=19
+ - icu >=78.3,<79.0a0
+ license: MIT
+ license_family: MIT
+ run_exports:
+ weak:
+ - libpsl >=0.23.1,<0.24.0a0
+ size: 72950
+ timestamp: 1786443660105
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libraqm-0.11.0-h45af499_0.conda
sha256: b110f7f9b2cec61ea793c521950414e00cd64826e18aeb4ab40369acf05c0039
md5: 46ea0eb4e71bffa35ab7070678bcb053
@@ -3711,6 +3995,19 @@ packages:
- libsqlite >=3.53.4,<4.0a0
size: 929203
timestamp: 1785016131414
+- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libssh2-1.11.1-hbf2880b_1.conda
+ sha256: a056e518c3d2d09fbb1778cea80c0c95338fb24adf1a817bbf90fb484850a304
+ md5: d957a8eda98c49b073e8dcfd677c127a
+ depends:
+ - libzlib >=1.3.2,<2.0a0
+ - openssl >=3.5.7,<4.0a0
+ license: BSD-3-Clause
+ license_family: BSD
+ run_exports:
+ weak:
+ - libssh2 >=1.11.1,<2.0a0
+ size: 280492
+ timestamp: 1786714226814
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/libtiff-4.7.2-h282da08_0.conda
sha256: 253153cabf9469170e02b21a6bc9aa598048e7c34966b1103af52d27d2a708a4
md5: 6fa87106b3c041ad6d965a9411e79b94
@@ -3839,6 +4136,35 @@ packages:
- ncurses >=6.6,<7.0a0
size: 805509
timestamp: 1777423252320
+- conda: https://conda.anaconda.org/conda-forge/osx-arm64/nspr-4.40-hdcbdcf5_0.conda
+ sha256: 429549e611c625d1f90714646b94aa62531be258b614414a54f6a402f8124c4a
+ md5: 7697df3a4af3427af9bc66dfaec228ae
+ depends:
+ - __osx >=11.0
+ - libcxx >=19
+ license: MPL-2.0
+ license_family: MOZILLA
+ run_exports:
+ weak:
+ - nspr >=4.40,<5.0a0
+ size: 202842
+ timestamp: 1786155286337
+- conda: https://conda.anaconda.org/conda-forge/osx-arm64/nss-3.118-h1c710a3_0.conda
+ sha256: d57f7b2cf2860a2a848e3dd43cc4f5488e60050a7d62af1834da3ee43911d9c4
+ md5: ae07409126ced4f0d982dfeab0681016
+ depends:
+ - __osx >=11.0
+ - libcxx >=19
+ - libsqlite >=3.51.0,<4.0a0
+ - libzlib >=1.3.1,<2.0a0
+ - nspr >=4.38,<5.0a0
+ license: MPL-2.0
+ license_family: MOZILLA
+ run_exports:
+ weak:
+ - nss >=3.118,<4.0a0
+ size: 1839904
+ timestamp: 1763486575227
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/numpy-2.5.1-py314hb79c6fa_0.conda
sha256: 3aa853ec05e6fe6b660be354fd05ab2a89b2e6cc6346612a6c75a18f38f62c3d
md5: 3587914062d5537dde5fa8c2131cf624
@@ -3936,6 +4262,37 @@ packages:
- pixman >=0.46.4,<1.0a0
size: 198717
timestamp: 1786106922508
+- conda: https://conda.anaconda.org/conda-forge/osx-arm64/poppler-26.07.0-h4cfec15_3.conda
+ sha256: c8784f244cc6cd33bf73b056ef04a3bc44be1d1257da4cf63381ffa358741fcf
+ md5: 0a477ba01d6418f51a114f63cb64a9b5
+ depends:
+ - __osx >=11.0
+ - cairo >=1.18.4,<2.0a0
+ - fontconfig >=2.18.1,<3.0a0
+ - fonts-conda-ecosystem
+ - lcms2 >=2.19.1,<3.0a0
+ - libcurl >=8.21.0,<9.0a0
+ - libcxx >=19
+ - libfreetype >=2.14.3
+ - libfreetype6 >=2.14.3
+ - libglib >=2.88.2,<3.0a0
+ - libiconv >=1.18,<2.0a0
+ - libintl >=0.25.1,<1.0a0
+ - libjpeg-turbo >=3.1.4.1,<4.0a0
+ - libpng >=1.6.58,<1.7.0a0
+ - libtiff >=4.7.2,<4.8.0a0
+ - libzlib >=1.3.2,<2.0a0
+ - nspr >=4.38,<5.0a0
+ - nss >=3.118,<4.0a0
+ - openjpeg >=2.5.4,<3.0a0
+ - poppler-data
+ license: GPL-2.0-or-later
+ license_family: GPL
+ run_exports:
+ weak:
+ - poppler >=26.7.0,<26.8.0a0
+ size: 1626453
+ timestamp: 1783345166234
- conda: https://conda.anaconda.org/conda-forge/osx-arm64/pthread-stubs-0.4-h84a0fba_1003.conda
sha256: 1c2338b9b0486af86883b9593d2f3e2845bbf216ea453dfe5d9a228e8dbe4057
md5: d4852e6054b74645cf49ca10f6349191
diff --git a/pixi.toml b/pixi.toml
index 57f2c3e..22aab04 100644
--- a/pixi.toml
+++ b/pixi.toml
@@ -16,7 +16,20 @@ test-lfortran = "bash scripts/build_lfortran.sh && mkdir -p tests/out && ./build
demo-lfortran = "bash scripts/build_lfortran.sh && ./build/lfortran/demo"
mpl-refs = "python tests/gen_mpl_refs.py"
-compare = "python tests/gen_mpl_refs.py && bash scripts/build_flang.sh && mkdir -p tests/out && ./build/flang/test_plots && python tests/compare_svgs.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.
+[tasks.compare]
+cmd = "python tests/compare_svgs.py"
+depends-on = ["mpl-refs", "test-flang"]
+
+[tasks.compare-png]
+cmd = "python tests/compare_pngs.py"
+depends-on = ["mpl-refs", "test-flang"]
+
+[tasks.compare-pdf]
+cmd = "python tests/compare_pdfs.py"
+depends-on = ["mpl-refs", "test-flang"]
[dependencies]
python = ">=3.14.6,<3.15"
@@ -24,6 +37,8 @@ matplotlib = ">=3.11.1,<4"
numpy = ">=2.5.1,<3"
cairosvg = ">=2.9.0,<3"
pillow = ">=12.3.0,<13"
+# pdftoppm, for rasterizing PDFs in tests/compare_pdfs.py
+poppler = "*"
lfortran = ">=0.64.0,<0.65"
[target.linux-64.dependencies]
diff --git a/scripts/build_flang.sh b/scripts/build_flang.sh
index cfd926e..399b303 100755
--- a/scripts/build_flang.sh
+++ b/scripts/build_flang.sh
@@ -16,21 +16,28 @@ cd "$BUILD"
# Compile modules in dependency order
$FLANG -c "$ROOT/src/fplot_colors.f90"
$FLANG -c "$ROOT/src/fplot_style.f90"
+$FLANG -c "$ROOT/src/fplot_render.f90"
$FLANG -c "$ROOT/src/fplot_scale.f90"
$FLANG -c "$ROOT/src/fplot_cmap.f90"
$FLANG -c "$ROOT/src/fplot_ticks.f90"
$FLANG -c "$ROOT/src/fplot_contour.f90"
$FLANG -c "$ROOT/src/fplot_svg.f90"
+$FLANG -c "$ROOT/src/fplot_backend_svg.f90"
+$FLANG -c "$ROOT/src/fplot_glyphs.f90"
+$FLANG -c "$ROOT/src/fplot_png.f90"
+$FLANG -c "$ROOT/src/fplot_raster.f90"
+$FLANG -c "$ROOT/src/fplot_backend_pdf.f90"
+$FLANG -c "$ROOT/src/fplot_backend_png.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_scale.o fplot_cmap.o fplot_ticks.o fplot_contour.o fplot_svg.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_glyphs.o fplot_png.o fplot_raster.o fplot_backend_png.o fplot.o
# Demo
$FLANG -o "$BUILD/demo" \
"$ROOT/examples/demo.f90" \
- fplot_colors.o fplot_style.o fplot_scale.o fplot_cmap.o fplot_ticks.o fplot_contour.o fplot_svg.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_glyphs.o fplot_png.o fplot_raster.o fplot_backend_png.o fplot.o
echo "Built: $BUILD/test_plots $BUILD/demo"
diff --git a/scripts/build_lfortran.sh b/scripts/build_lfortran.sh
index bd88d93..72fc696 100755
--- a/scripts/build_lfortran.sh
+++ b/scripts/build_lfortran.sh
@@ -13,20 +13,27 @@ cd "$BUILD"
# Prefer a single shared-module build
$LFORTRAN -c "$ROOT/src/fplot_colors.f90"
$LFORTRAN -c "$ROOT/src/fplot_style.f90"
+$LFORTRAN -c "$ROOT/src/fplot_render.f90"
$LFORTRAN -c "$ROOT/src/fplot_scale.f90"
$LFORTRAN -c "$ROOT/src/fplot_cmap.f90"
$LFORTRAN -c "$ROOT/src/fplot_ticks.f90"
$LFORTRAN -c "$ROOT/src/fplot_contour.f90"
$LFORTRAN -c "$ROOT/src/fplot_svg.f90"
+$LFORTRAN -c "$ROOT/src/fplot_backend_svg.f90"
+$LFORTRAN -c "$ROOT/src/fplot_glyphs.f90"
+$LFORTRAN -c "$ROOT/src/fplot_png.f90"
+$LFORTRAN -c "$ROOT/src/fplot_raster.f90"
+$LFORTRAN -c "$ROOT/src/fplot_backend_pdf.f90"
+$LFORTRAN -c "$ROOT/src/fplot_backend_png.f90"
$LFORTRAN -c "$ROOT/src/fplot.f90"
$LFORTRAN -o "$BUILD/test_plots" \
"$ROOT/tests/test_plots.f90" \
- fplot_colors.o fplot_style.o fplot_scale.o fplot_cmap.o fplot_ticks.o fplot_contour.o fplot_svg.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_glyphs.o fplot_png.o fplot_raster.o fplot_backend_png.o fplot.o
$LFORTRAN -o "$BUILD/demo" \
"$ROOT/examples/demo.f90" \
- fplot_colors.o fplot_style.o fplot_scale.o fplot_cmap.o fplot_ticks.o fplot_contour.o fplot_svg.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_glyphs.o fplot_png.o fplot_raster.o fplot_backend_png.o fplot.o
echo "Built: $BUILD/test_plots $BUILD/demo"
echo "Jupyter: use display_data('image/svg+xml', render_svg()) with lfortran_display"
diff --git a/src/fplot.f90 b/src/fplot.f90
index 8e151f4..f24761d 100644
--- a/src/fplot.f90
+++ b/src/fplot.f90
@@ -7,6 +7,10 @@ module fplot
use fplot_contour
use fplot_ticks
use fplot_svg
+ use fplot_render
+ use fplot_backend_svg
+ use fplot_backend_pdf
+ use fplot_backend_png
implicit none
private
@@ -21,7 +25,7 @@ module fplot
public :: imshow, colorbar, contour, contourf
public :: title, xlabel, ylabel, grid, legend
public :: xlim, ylim, clf, savefig, show, figure
- public :: render_svg
+ public :: render_svg, render_pdf, render_png
public :: subplot, suptitle, subplots_adjust, tight_layout
public :: twinx, twiny
public :: set_fontsize
@@ -218,6 +222,9 @@ module fplot
real(dp), save :: def_title = TITLE_FONT, def_label = LABEL_FONT
real(dp), save :: def_tick = TICK_FONT, def_legend = LEGEND_FONT
real(dp), save :: fig_suptitle_size = SUPTITLE_FONT
+
+ ! Clipping region currently in force. See set_clip.
+ type(clip_t), save :: g_clip
type(axes_t), allocatable, save :: ax(:)
integer, save :: n_ax = 0
integer, save :: cur_i = 0
@@ -2185,15 +2192,6 @@ pure function axis_frac(v, vmin, vmax, sc) result(t)
end if
end function axis_frac
- subroutine append_num(b, x)
- type(svg_builder), intent(inout) :: b
- real(dp), intent(in) :: x
- character(len=64) :: s
- integer :: n
- call fmt_num(x, s, n)
- call builder_append(b, s(1:n))
- end subroutine append_num
-
pure function int_to_str(i) result(s)
integer, intent(in) :: i
character(len=:), allocatable :: s
@@ -2202,243 +2200,354 @@ pure function int_to_str(i) result(s)
s = trim(tmp)
end function int_to_str
- subroutine append_dash(b, ls)
- type(svg_builder), intent(inout) :: b
+ ! fplot carries colors as "#rrggbb" because that is what a format string
+ ! and a colormap table both produce; the renderer wants components.
+ pure function hex_rgb(s) result(c)
+ character(len=*), intent(in) :: s
+ integer :: c(3), i
+ c = 0
+ if (len(s) < 7) return
+ do i = 1, 3
+ c(i) = hex_byte(s(2*i:2*i + 1))
+ end do
+ end function hex_rgb
+
+ ! The clip in force for the primitives being emitted now. The rendering
+ ! API is stateless by design, but fplot draws in regions ("everything
+ ! inside the axes box"), so the front end tracks the current region here
+ ! and stamps it into each paint rather than passing it through fifteen
+ ! layers of call.
+ subroutine set_clip(x, y, w, h)
+ real(dp), intent(in) :: x, y, w, h
+ g_clip%on = .true.
+ g_clip%x = x
+ g_clip%y = y
+ g_clip%w = w
+ g_clip%h = h
+ end subroutine set_clip
+
+ subroutine clear_clip()
+ g_clip%on = .false.
+ end subroutine clear_clip
+
+ ! Stroke-only paint.
+ function pen(color, lw, alpha, ls) result(p)
+ character(len=*), intent(in) :: color
+ real(dp), intent(in) :: lw
+ real(dp), intent(in), optional :: alpha
+ integer, intent(in), optional :: ls
+ type(paint_t) :: p
+ p%filled = .false.
+ p%stroked = .true.
+ p%stroke_rgb = hex_rgb(color)
+ p%line_width = lw
+ if (present(alpha)) p%stroke_alpha = alpha
+ if (present(ls)) call set_dash(p, ls)
+ p%clip = g_clip
+ end function pen
+
+ ! Fill-only paint.
+ function brush(color, alpha) result(p)
+ character(len=*), intent(in) :: color
+ real(dp), intent(in), optional :: alpha
+ type(paint_t) :: p
+ p%filled = .true.
+ p%stroked = .false.
+ p%fill_rgb = hex_rgb(color)
+ if (present(alpha)) p%fill_alpha = alpha
+ p%clip = g_clip
+ end function brush
+
+ ! matplotlib's dash patterns, in points, for its four line styles.
+ subroutine set_dash(p, ls)
+ type(paint_t), intent(inout) :: p
integer, intent(in) :: ls
select case (ls)
case (LINE_DASHED)
- call builder_append(b, ' stroke-dasharray="5.55,2.4"')
+ p%n_dash = 2
+ p%dash(1:2) = [5.55_dp, 2.4_dp]
case (LINE_DOTTED)
- call builder_append(b, ' stroke-dasharray="1.5,2.475"')
+ p%n_dash = 2
+ p%dash(1:2) = [1.5_dp, 2.475_dp]
case (LINE_DASHDOT)
- call builder_append(b, ' stroke-dasharray="9.9,2.4,1.5,2.4"')
+ p%n_dash = 4
+ p%dash(1:4) = [9.9_dp, 2.4_dp, 1.5_dp, 2.4_dp]
end select
- end subroutine append_dash
-
- ! Emit a stroked open path through the given points, e.g. an "x" or "+".
- ! matplotlib writes stroke-opacity/fill-opacity per element rather than a
- ! group opacity; emitting nothing at alpha == 1 keeps the common case terse.
- subroutine append_opacity(b, attr, alpha)
- type(svg_builder), intent(inout) :: b
- character(len=*), intent(in) :: attr
- real(dp), intent(in) :: alpha
- if (alpha >= 1.0_dp) return
- call builder_append(b, '" ')
- call builder_append(b, attr)
- call builder_append(b, '="')
- call append_num(b, alpha)
- end subroutine append_opacity
+ end subroutine set_dash
+
+ ! Verbs for an open polyline through np points.
+ pure function line_verbs(np) result(v)
+ integer, intent(in) :: np
+ integer :: v(np), i
+ v(1) = VERB_MOVE
+ do i = 2, np
+ v(i) = VERB_LINE
+ end do
+ end function line_verbs
subroutine append_stroke_path(b, px, py, np, color, lw, alpha)
- type(svg_builder), intent(inout) :: b
+ class(renderer_t), intent(inout) :: b
real(dp), intent(in) :: px(:), py(:)
integer, intent(in) :: np
character(len=*), intent(in) :: color
real(dp), intent(in) :: lw, alpha
- integer :: i
- call builder_append(b, '')
- call builder_append(b, new_line("a"))
+ if (np < 2) return
+ call b%draw_path(px(1:np), py(1:np), line_verbs(np), np, &
+ pen(color, lw, alpha))
end subroutine append_stroke_path
- ! Emit a filled closed polygon, used by the shaped markers and by
- ! fill_between.
+ ! A filled closed polygon, used by the shaped markers and by fill_between.
subroutine append_polygon(b, px, py, np, color, alpha, seal)
- type(svg_builder), intent(inout) :: b
+ class(renderer_t), intent(inout) :: b
real(dp), intent(in) :: px(:), py(:)
integer, intent(in) :: np
character(len=*), intent(in) :: color
real(dp), intent(in) :: alpha
logical, intent(in), optional :: seal
- integer :: i
- call builder_append(b, '')
- call builder_append(b, new_line("a"))
+ call b%draw_path(px(1:np), py(1:np), v, np + 1, p)
end subroutine append_polygon
- ! Draw one marker of kind mk centred at (cx, cy), sized like a matplotlib
- ! marker of markersize ms.
- subroutine append_marker(b, mk, cx, cy, ms, color, alpha)
- type(svg_builder), intent(inout) :: b
+ ! The outline of one marker, described about the origin, together with
+ ! how it should be painted. Handing the renderer a shape plus a list of
+ ! positions lets every backend name the outline once and then reference
+ ! it: an SVG