Annotations
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()
Warning: sysroot "/Applications/Xcode_12.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk" not found (ignoring for now).
Vapor 3.9.3
Python 3.9.19 (/opt/anaconda3/envs/vapor)
OpenGL 4.1 Metal - 83.1
Vapor Colorbars
# Show the basic colorbar annotation for a renderer
colorbar = ren.GetColorbarAnnotation()
colorbar.SetEnabled(True)
ses.Show()
![../_images/262c154a820a8b1e74829aa105f53a739ba3cec455dfb6c63ca02b802550fe1e.png](../_images/262c154a820a8b1e74829aa105f53a739ba3cec455dfb6c63ca02b802550fe1e.png)
# 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
![../_images/9b3e8d0620c3dc9684570d587d7a9d54d18ff4752ff1eb4bcbc2825297683765.png](../_images/9b3e8d0620c3dc9684570d587d7a9d54d18ff4752ff1eb4bcbc2825297683765.png)
MatPlotLib Colorbars
You can customize the histograms as you would MatPlotLib’s pylab.colorbar
tf = ren.GetPrimaryTransferFunction()
tf.ShowMatPlotLibColorbar()
![../_images/cd3e3e9805e98dc2566dd873789a492b87a911143adc6c86247044f4ccfb61b1.png](../_images/cd3e3e9805e98dc2566dd873789a492b87a911143adc6c86247044f4ccfb61b1.png)
tf.ShowMatPlotLibColorbar(orientation="vertical", figsize=(1.5,4))
![../_images/1a2dea9347b918ce2741cf5186b9d7d2bd31f4c167d3cd27bbe515a17d2a0223.png](../_images/1a2dea9347b918ce2741cf5186b9d7d2bd31f4c167d3cd27bbe515a17d2a0223.png)
# The MatPlotLib Colorbars are automatically synced to Vapor's transfer functions
tf.LoadBuiltinColormap(tf.ListBuiltinColormaps()[7])
ses.Show()
tf.ShowMatPlotLibColorbar()
![../_images/6d0c18d6f678ae69ab989d8ae0f3da64b4511171f51a191c75ce1d95814e9820.png](../_images/6d0c18d6f678ae69ab989d8ae0f3da64b4511171f51a191c75ce1d95814e9820.png)
![../_images/d21b0cd2e0bba72440a5268850c123274ebf918b707de906b07d1be855e2b2e8.png](../_images/d21b0cd2e0bba72440a5268850c123274ebf918b707de906b07d1be855e2b2e8.png)
colorbar.SetEnabled(False)
MatPlotLib Histograms
histogram.ShowMatPlotLibHistogram(ses, ren)
![../_images/4a104fff93b50e17bf5a30bee1253ea1f8240652ee9d7b22009514b1f0cac5eb.png](../_images/4a104fff93b50e17bf5a30bee1253ea1f8240652ee9d7b22009514b1f0cac5eb.png)
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()
![../_images/5bfbc044f686c9356e3b0738b1c1adfadac1e757bf2698e6ce14461b0c65f841.png](../_images/5bfbc044f686c9356e3b0738b1c1adfadac1e757bf2698e6ce14461b0c65f841.png)
Axis Annotations
axis = ses.GetAxisAnnotations()
axis.SetAxisAnnotationEnabled(True)
ses.Show()
![../_images/1b5624ed01d237a2f4aa6f4dbd441cf3fa65f83623a0ff3a0974abd35430dae1.png](../_images/1b5624ed01d237a2f4aa6f4dbd441cf3fa65f83623a0ff3a0974abd35430dae1.png)
axis.SetNumTics((5,5))
axis.SetAxisFontSize(24)
ses.Show()
# This example dataset is not geo-referenced
# axis.SetLatLonAxesEnabled(True)
![../_images/5fb5272886e2a1cece516ad0c50e6c5f23446952689b23f95a1553e6d9a20576.png](../_images/5fb5272886e2a1cece516ad0c50e6c5f23446952689b23f95a1553e6d9a20576.png)
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()
![../_images/4c64d2556ffb62abdad674793379c0c64452425ebec7863a98c67f6922c4b3b8.png](../_images/4c64d2556ffb62abdad674793379c0c64452425ebec7863a98c67f6922c4b3b8.png)
scene.SetAxisArrowEnabled(True)
scene.SetAxisArrowSize(0.4)
scene.SetTimeType(scene.TimeAnnotationType.Timestep)
scene.SetTimeColor((0,0,0))
scene.SetTimeLLX(0.7)
ses.Show()
![../_images/fb2dc50632e48016344f40ecb7f101ef48855183d4bd115fddfec02fb82ba4f1.png](../_images/fb2dc50632e48016344f40ecb7f101ef48855183d4bd115fddfec02fb82ba4f1.png)