Skip to article frontmatterSkip to article content

You can annotate your renderings using Vapor’s build in annotations as well as MatPlotLib

import example_utils
from vapor import session, renderer, dataset, camera
from vapor.utils import histogram

ses = session.Session()
data = example_utils.OpenExampleDataset(ses)

ren = data.NewRenderer(renderer.TwoDDataRenderer)
ren.SetVariableName(data.GetDataVarNames(2)[1])
ses.GetCamera().ViewAll()
Vapor 3.10.0
Python 3.9.19 (/opt/anaconda3/envs/vapor)
OpenGL 4.1 Metal - 89.3

Vapor Colorbars

# Show the basic colorbar annotation for a renderer
colorbar = ren.GetColorbarAnnotation()
colorbar.SetEnabled(True)
ses.Show()
<PIL.Image.Image image mode=RGB size=600x480>
# Customized colorbar annotation
colorbar.SetSize((0.2, 0.25))
colorbar.SetTitle("Colorbar Title")
colorbar.SetCornerPosition((0.95, 0.95))
ses.Show()
UNSUPPORTED (log once): POSSIBLE ISSUE: unit 0 GLD_TEXTURE_INDEX_2D is unloadable and bound to sampler type (Float) - using zero texture because texture unloadable
<PIL.Image.Image image mode=RGB size=600x480>

MatPlotLib Colorbars

You can customize the histograms as you would MatPlotLib’s pylab.colorbar

tf = ren.GetPrimaryTransferFunction()
tf.ShowMatPlotLibColorbar()
<Figure size 900x150 with 2 Axes>
tf.ShowMatPlotLibColorbar(orientation="vertical", figsize=(1.5,4))
<Figure size 150x400 with 2 Axes>
# The MatPlotLib Colorbars are automatically synced to Vapor's transfer functions
tf.LoadBuiltinColormap(tf.ListBuiltinColormaps()[7])
ses.Show()
tf.ShowMatPlotLibColorbar()
<PIL.Image.Image image mode=RGB size=600x480><Figure size 900x150 with 2 Axes>
colorbar.SetEnabled(False)

MatPlotLib Histograms

histogram.ShowMatPlotLibHistogram(ses, ren)
<Figure size 640x480 with 1 Axes>

You can customize the histograms as you would matplotlib.pyplot.hist

plt = histogram.GetMatPlotLibHistogram(ses, ren, color ="red")
plt.xlabel("X-Axis")
plt.ylabel("Y-Axis")
plt.title("Title\n", fontweight="bold")
plt.show()
<Figure size 640x480 with 1 Axes>

Axis Annotations

axis = ses.GetAxisAnnotations()
axis.SetAxisAnnotationEnabled(True)
ses.Show()
<PIL.Image.Image image mode=RGB size=600x480>
axis.SetNumTics((5,5))
axis.SetAxisFontSize(24)
ses.Show()

# This example dataset is not geo-referenced
# axis.SetLatLonAxesEnabled(True)
<PIL.Image.Image image mode=RGB size=600x480>
axis.SetAxisAnnotationEnabled(False)

Scene Annotations

Scene annotations are other annotations and rendering options that apply to the entire rendering such as background color.

scene = ses.GetSceneAnnotations()
scene.SetBackgroundColor((1,1,1))
scene.SetUseDomainFrame(False)
ses.Show()
<PIL.Image.Image image mode=RGB size=600x480>
scene.SetAxisArrowEnabled(True)
scene.SetAxisArrowSize(0.4)

scene.SetTimeType(scene.TimeAnnotationType.Timestep)
scene.SetTimeColor((0,0,0))
scene.SetTimeLLX(0.7)

ses.Show()
<PIL.Image.Image image mode=RGB size=600x480>