Cleopatra
Cleopatra is a matplotlib utility package for visualizing 2D/3D numpy arrays, unstructured meshes, point clouds, vector fields, polygons, lines, and statistical distributions. It targets scientific and research users working with geospatial and raster data, providing a high-level API over matplotlib with sensible defaults and rich customization.
For the package's boundaries — what belongs here and what does not — see SCOPE.md.
Package Layout
graph TD
subgraph core["Core"]
glyph["<b>glyph</b><br/>Glyph — base class<br/>figure/axes · color norms · classification<br/>colorbars · ticks · point overlays · animation"]
end
subgraph geomixin["Geo mixin"]
geo["<b>geo</b><br/>GeoMixin — crs · add_tiles<br/>add_features · add_relief<br/>add_reference_map · add_labels"]
end
subgraph visualizers["Visualizers — subclass Glyph"]
array_glyph["<b>array_glyph</b><br/>ArrayGlyph · FacetGrid<br/>2D/3D rasters, facets, animation"]
mesh_glyph["<b>mesh_glyph</b><br/>MeshGlyph<br/>unstructured meshes"]
scatter_glyph["<b>scatter_glyph</b><br/>ScatterGlyph<br/>point clouds"]
vector_glyph["<b>vector_glyph</b><br/>VectorGlyph<br/>vector fields"]
flow_glyph["<b>flow_glyph</b><br/>FlowGlyph<br/>flow paths"]
line_glyph["<b>line_glyph</b><br/>LineGlyph<br/>line / bar / band"]
polygon_glyph["<b>polygon_glyph</b><br/>PolygonGlyph<br/>polygon collections"]
kde_glyph["<b>kde_glyph</b><br/>KDEGlyph<br/>2D kernel density"]
end
subgraph standalone["Standalone"]
statistical_glyph["<b>statistical_glyph</b><br/>StatisticalGlyph<br/>histogram · boxplot · multiboxplot · stripes"]
end
subgraph support["Supporting utilities"]
styles["<b>styles</b><br/>Styles · Scale · ColorScale<br/>MidpointNormalize · classify · resolve_sizes · legends"]
colors["<b>colors</b><br/>Colors · haze data styles<br/>hex/RGB · colormaps · alpha-scaled layers"]
animation["<b>animation</b><br/>save_animation · to_gif/mp4 · embed_gif<br/>GIF/WebP/MP4/MOV/AVI · bundled ffmpeg"]
projection["<b>projection</b><br/>apply_projection_frame<br/>orthographic globe presets"]
config["<b>config</b><br/>Config — matplotlib backend helper"]
end
subgraph optional["Optional — cleopatra[tiles]"]
tiles["<b>tiles</b><br/>add_tiles · fetch / stitch helpers<br/>XYZ web-tile basemaps"]
reference["<b>reference</b><br/>add_features · add_relief<br/>Natural Earth · hypsometric relief"]
end
array_glyph & mesh_glyph & scatter_glyph & vector_glyph & flow_glyph & line_glyph & polygon_glyph & kde_glyph ==>|extends| glyph
array_glyph & mesh_glyph & scatter_glyph & vector_glyph & flow_glyph & polygon_glyph -.->|mixes in| geo
geo -->|basemap tiles| tiles
geo -->|coastlines · relief| reference
glyph -->|color scales · classification| styles
glyph -->|save / embed| animation
glyphprovides the sharedGlyphbase class (figure/axes lifecycle, colorbars, color norms, ticks, classification, animation).- The user-facing visualizers all subclass
Glyphand share its colour-mapping/colorbar pipeline —array_glyph(ArrayGlyph,FacetGrid),mesh_glyph(MeshGlyph),scatter_glyph(ScatterGlyph),vector_glyph(VectorGlyph),flow_glyph(FlowGlyph),line_glyph(LineGlyph),polygon_glyph(PolygonGlyph), andkde_glyph(KDEGlyph).statistical_glyph(StatisticalGlyph) stands alone. geoprovidesGeoMixin, mixed into the six geographic visualizers —array_glyph,mesh_glyph,scatter_glyph,vector_glyph,flow_glyph, andpolygon_glyph(notline_glyph,kde_glyph, orstatistical_glyph) — adding a settablecrsplus one-call basemap helpers on the glyph's own axes:add_tiles,add_features,add_relief,add_reference_map, andadd_labels.tilesandreferenceare the optional (cleopatra[tiles]) basemap data sourcesgeowraps —tilesfetches/stitches XYZ web-tile mosaics,referencedraws fixed public Natural Earth vector layers and a hypsometric relief raster.colors,styles,animation,projection, andconfigare supporting utilities (colour conversions plus composable "haze"-style data layers viaapply_data_styleand alpha-scaled image/mesh rendering; predefined styles,MidpointNormalize,ColorScale, value→size mapping,classifyclassification schemes and legend builders; glyph-independent animation save/embed helpers spanning GIF/WebP/MP4/MOV/AVI with a bundled-ffmpeg fallback; static projected map frames plus orthographic globe reprojection presets; and the matplotlib-backend helper).
Main Features
ArrayGlyph -- Raster / Array Visualization
- Plot 2D numpy arrays with automatic colorbar and customizable color scales (linear, power, symmetric log-norm, boundary-norm, midpoint).
- Display cell values and overlay point markers on the plot.
- Animate 3D single-band stacks or 4D RGB/RGBA true-colour stacks over time, and export to GIF, WebP, MP4, MOV, or AVI (bundled ffmpeg -- no separate install needed).
- Drop in an ECMWF/CAMS-style basemap (coastlines, borders, graticule) with a single
add_reference_mapcall.
MeshGlyph -- Unstructured Mesh Visualization
- Visualize UGRID-style unstructured mesh data using triangulation (
tripcolor,tricontourf). - Render wireframe outlines via
LineCollection. - Accepts raw numpy arrays of node coordinates and face-node connectivity.
- Animate time-varying mesh data.
StatisticalGlyph -- Distribution Plots
- Create histograms for 1D and 2D datasets with customizable bins, colors, and transparency.
- Draw boxplots, multi-boxplots, and strip plots.
ScatterGlyph -- Point Clouds
- Plot 2D point clouds, colour-mapped by a per-point
valuesarray with a matching colorbar. - Encode a second quantity through per-point marker
sizes(with an optional size legend), so colour and size carry two variables at once.
VectorGlyph -- Vector Fields
- Render 2D
(u, v)vector fields as arrows (quiver), wind barbs, or streamlines. - Colour the artist by vector magnitude
hypot(u, v)through the shared scalar-mapping pipeline.
FlowGlyph -- Flow Paths
- Draw a sequence of polylines as a
LineCollection, colour-mapped by a per-pathvaluesarray. - Scale per-path line widths by magnitude, with an optional width legend.
LineGlyph -- Line / Bar / Band Plots
- Line, bar, and
fill_between(band) plots.lineaccepts 1D or 2Dy(one series per column);bartakes a single 1D series.
PolygonGlyph -- Polygon Collections
- Fill and colour-map collections of polygons by a per-polygon
valuesarray, or draw outlines only.
KDEGlyph -- Kernel Density
- Estimate a 2D Gaussian kernel density of an
(x, y)point cloud (NumPy only, no scipy) and draw it as filled or line density contours.
Geospatial basemaps -- GeoMixin
ArrayGlyph,MeshGlyph,ScatterGlyph,VectorGlyph,FlowGlyph, andPolygonGlyphmix inGeoMixin, adding a settablecrsplus one-call basemap helpers onglyph.ax:add_tiles(XYZ web-tile mosaics),add_features/add_relief(Natural Earth coastlines, borders, land, ocean, rivers, lakes, and a hypsometric relief backdrop), a one-calladd_reference_mappreset ("ecmwf","ecmwf-dark", or"auto"), andadd_labelsfor city/point labels.tilesand the fixed-public-datasetreferencelayers require thecleopatra[tiles]extra.
Composable data styles & globe projections
colors.apply_data_stylerenders one or more layers with a named preset (currently"haze", an aerosol / organic-matter / dust look) -- per-pixel opacity tied to value viaalpha_scaled_image/alpha_scaled_mesh, plus a swatch legend, in one call.projection.apply_projection_stylereprojects(lon, lat, data)onto an orthographic "globe" view (or leaves it flat) via named presets, pairing withapply_data_styleto build ECMWF/CAMS-style globe animations in a few lines. The orthographic helpers require thecleopatra[tiles]extra (pyproj).
Colors -- Color Utilities
- Convert between hex, RGB (0-255), and normalized RGB (0-1) formats.
- Extract color ramps from images and create custom matplotlib colormaps.
- Ready-made "haze" colormaps and alpha-scaled rendering helpers for the composable data styles above.
Installation
pip
pip install cleopatra
# with the optional web-tile basemap support (cleopatra.tiles.add_tiles)
pip install "cleopatra[tiles]"
conda
conda install -c conda-forge cleopatra
# with the optional web-tile basemap support
conda install -c conda-forge cleopatra-tiles
The conda packages are built from the
cleopatra-feedstock
(the cleopatra-tiles output bundles pillow, pyproj, and xyzservices).
From source (latest development version)
pip install git+https://github.com/serapeum-org/cleopatra
Quick Start
Plot a 2D array
import numpy as np
from cleopatra.array_glyph import ArrayGlyph
arr = np.random.rand(10, 10)
glyph = ArrayGlyph(arr)
fig, ax = glyph.plot(title="Random Array")
Create a histogram
import numpy as np
from cleopatra.statistical_glyph import StatisticalGlyph
data = np.random.normal(0, 1, 1000)
stat = StatisticalGlyph(data)
fig, ax = stat.histogram(bins=30)
Plot an unstructured mesh
import numpy as np
from cleopatra.mesh_glyph import MeshGlyph
node_x = np.array([0.0, 1.0, 0.5, 1.5])
node_y = np.array([0.0, 0.0, 1.0, 1.0])
face_nodes = np.array([[0, 1, 2], [1, 3, 2]])
face_data = np.array([10.0, 20.0])
mg = MeshGlyph(node_x, node_y, face_nodes)
fig, ax = mg.plot(face_data, location="face", title="Mesh Data")
Plot a value-coloured point cloud
import numpy as np
from cleopatra.scatter_glyph import ScatterGlyph
x = np.random.rand(100)
y = np.random.rand(100)
values = np.random.rand(100)
sg = ScatterGlyph(x, y, values=values)
fig, ax, sc = sg.plot(title="Scatter")
Plot a vector field
import numpy as np
from cleopatra.vector_glyph import VectorGlyph
x, y = np.meshgrid(np.linspace(0, 1, 8), np.linspace(0, 1, 8))
u, v = np.cos(x), np.sin(y)
vg = VectorGlyph(x, y, u, v)
fig, ax, artist = vg.plot(kind="quiver", title="Vector Field")
Add a basemap to an array plot
import numpy as np
from cleopatra.array_glyph import ArrayGlyph
field = np.random.rand(80, 120)
glyph = ArrayGlyph(field, extent=[-100, 15, -40, 55]) # west, south, east, north
glyph.plot(cmap="turbo", cbar_label="anomaly")
glyph.add_reference_map("ecmwf") # coastlines, borders, and a lon/lat graticule
Requirements
- Python >= 3.11
- numpy >= 2.0.0
- matplotlib >= 3.9
Ships with a bundled ffmpeg binary (via imageio-ffmpeg), so save_animation can export MP4/MOV/AVI without a
separate system install. Geospatial basemaps and globe-projection presets (GeoMixin, cleopatra.tiles,
cleopatra.reference, and the orthographic helpers in cleopatra.projection) need the cleopatra[tiles] extra.
Documentation
Full documentation is available at serapeum-org.github.io/cleopatra.
License
Cleopatra is licensed under the GNU General Public License v3.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cleopatra-0.28.0.tar.gz.
File metadata
- Download URL: cleopatra-0.28.0.tar.gz
- Upload date:
- Size: 4.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d27da464e03a45762a624e8efc22fc7af5750935a9fe390edf6b8b1aa3654174
|
|
| MD5 |
4d4d031821573d5ced3f679bdcd31b2d
|
|
| BLAKE2b-256 |
43752d75ba2d872d200cb6bf309e89f2ebb96b7c22984296fd9ba1b4299dcbd9
|
File details
Details for the file cleopatra-0.28.0-py3-none-any.whl.
File metadata
- Download URL: cleopatra-0.28.0-py3-none-any.whl
- Upload date:
- Size: 283.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df0434d5501c5aa85eddc2cba4466437608d325aa47d27639d442a583b79155e
|
|
| MD5 |
d03aad47acb7cc064dc5381937a33b60
|
|
| BLAKE2b-256 |
dcc6c993e8f3129975c2a60c87c4489d432ad203390c04f606f19b9ec2ad5d58
|