cf-plot allows you to produce and customise publication-quality contour, vector, line and more plots with the power of Python, matplotlib, Cartopy and cf-python, in as few lines of code as possible.
It is designed to be a useful visualisation tool for environmental, earth and aligned sciences, for example to facilitate climate and meteorological research. cf-plot is developed and maintained by the NCAS-CMS group, part of NCAS.
In as little as four lines of Python including imports and file reading,
using cf-plot you can for example produce a contour plot showing a 2D
subspace of a netCDF dataset:
import cf
import cfplot as cfp
f = cf.read('<dataset name>.nc')[0] # picks out a read-in field of the dataset
cfp.con(f.subspace(time=<chosen time value>)) # creates a contour plot of the field at that time valueA gallery of outputs made with cf-plot, showcasing a range of plotting possibilities with links to relevant documentation pages and to example code, can be found on this dedicated page within the documentation, as illustrated in the (static) image at the top of this document.
See the cf-plot homepage
(https://ncas-cms.github.io/cf-plot) for the full online documentation.
To install cf-plot with its required dependencies, you can use pip:
pip install cf-python cf-plotor you can use conda (or similar package managers such
as mamba) as follows (or equivalent):
conda install -c ncas -c conda-forge cf-python cf-plot udunits2More detail about installation is provided on the
installation page
(https://ncas-cms.github.io/cf-plot/installation.html)
of the documentation.
If image tests fail after an environment change, inspect the reference, generated plot and failure diff before accepting the differences. From the repository root, generate fresh plots using your testing environment:
python -m pytest tests/integration/test_contour_plot_examples.py tests/integration/test_advanced_plot_examples.pyFor a complete refresh, avoid -k or :: selectors: targeted runs preserve
old generated images. The
reference refresh script previews
updates by default. Select examples by filename suffix (for example,
gen_fig_16b.png has ID 16b):
python scripts/refresh_image_references.py 4 5 16b
# After visually approving these generated plots:
python scripts/refresh_image_references.py 4 5 16b --writeUse --all instead of example IDs to preview every available generated
baseline, then --all --write only after reviewing all selected plots.
The script validates the selection before writing, replaces existing
references, and removes only their failure-diff images; generated plots
are retained. It does not render or automatically approve plots.
Rerun the image tests afterward to verify the updated references and clear pytest's recorded failures. Review and commit the reference-image changes; do not accept a genuine plotting regression merely to make tests pass.
Everyone is welcome to contribute to cf-plot in the form of bug reports, documentation, code, design proposals, and more.
Contributing guidelines are available in a dedicated document which is copied into the documentation here.
For any queries, see the
guidance page
(https://ncas-cms.github.io/cf-plot/support.html).
