Plotly: 2-D height surfaces and 3-D isosurfaces¶
Download the example bundle
and run from the extracted directory. The small synthetic data files are
generated by tests/generate_test_data.py and already included in the bundle.
All coordinates and scalar amplitudes in these examples are dimensionless.
For a two-dimensional field, plotly draws the scalar value as a height
above the x–y plane. A three-dimensional field instead uses nested isosurfaces
inside the volume. surface_count and opacity determine how many
surfaces appear and how well the interior can be seen.
The HTML figures below are interactive: drag to rotate, scroll to zoom, and hover to inspect values. Python and CLI outputs have exactly matching trace data, layouts, and configurations; browser rasterization can depend on the reader’s graphics hardware. HTML IDs are randomly generated and are excluded from that comparison. No Chrome/Kaleido installation is needed to generate these HTML examples. Viewing them requires network access to the Plotly runtime CDN.
Python script
python examples/scripts/08_plotly.py
"""Interactive height surfaces from 2D data and isosurfaces from a 3D field."""
import postgkyl as pg
from _example_paths import TEST_DATA, prepare_output_dir
OUTPUT_DIR = prepare_output_dir()
surface = pg.load(TEST_DATA / "generated/wave_surface_000.gkyl").interpolate()
surface.plotly(background="light",
title="Travelling-wave height surface",
xlabel="x",
ylabel="y",
zlabel="Density [normalized]",
clabel="Density",
saveas=str(OUTPUT_DIR / "08_surface.html"))
volume = pg.load(TEST_DATA / "generated/gaussian_volume.gkyl").interpolate()
volume.plotly(background="light",
title="Gaussian density isosurfaces",
xlabel="x",
ylabel="y",
zlabel="z",
clabel="Density",
surface_count=8,
opacity=0.15,
cmin=0.1,
cmax=0.9,
saveas=str(OUTPUT_DIR / "08_volume.html"))
Equivalent CLI commands
Run from the extracted example bundle (or repository root). Create an output directory first:
mkdir -p output
pgkyl tests/test_data/generated/wave_surface_000.gkyl interpolate plotly --background light \
--title 'Travelling-wave height surface' --xlabel x --ylabel y --zlabel \
'Density [normalized]' --clabel Density --saveas output/08_surface.html
08_surface.html: Identical Plotly traces, layout, and configuration.
Python: open interactive figure.
CLI: open interactive figure.
pgkyl tests/test_data/generated/gaussian_volume.gkyl interpolate plotly --background light \
--title 'Gaussian density isosurfaces' --xlabel x --ylabel y --zlabel z --clabel \
Density --surface_count 8 --opacity 0.15 --cmin 0.1 --cmax 0.9 --saveas \
output/08_volume.html
08_volume.html: Identical Plotly traces, layout, and configuration.
Python: open interactive figure.
CLI: open interactive figure.