Skip to content

fix: labels visibility issue#474

Merged
AlejandroFernandezLuces merged 2 commits intomainfrom
fix/labeling-visibility-issue
Feb 18, 2026
Merged

fix: labels visibility issue#474
AlejandroFernandezLuces merged 2 commits intomainfrom
fix/labeling-visibility-issue

Conversation

@moe-ad
Copy link
Contributor

@moe-ad moe-ad commented Feb 17, 2026

This is a tricky one which I have been investigating since yesterday. Even trickier to describe but I will try my best.

Consider this code snippet

import pyvista as pv
from ansys.tools.visualization_interface import Plotter

plotter = Plotter()
sphere = pv.Sphere(radius=0.5, center=(0.5, 0.5, 0))
plotter.plot(sphere)

points = [[0, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0], [0.5, 0.5, 0.5]]
labels = ['A', 'B', 'C', 'D', 'E']

# Adding labels on at a time
for i, (pt, lbl) in enumerate(zip(points, labels)):
    # Pass font_size, point_size, and other kwargs
    plotter.add_labels([pt], [lbl], font_size=20, point_size=10, bold=True)

print(f"Total actors in scene: {len(plotter._backend.base_plotter.actors)}")
plotter.show()

Now one would expect 11 actors to be present on this scene (1 sphere, 5 points, 5 labels), but the running this code produces random results every single time as shown in the ffl examples (you can also trying running the snippet locally from the main branch):

Number of reported actors on the scene Corresponding plot
3 image
5 image
3 image

As you can see, labels are being randomly dropped from the scene.

However, this bug doesn't occur when you go through pyvista directly. You can confirm that by running the ffl:

import pyvista as pv

pl = pv.Plotter()
pl.add_mesh(pv.Sphere(radius=0.5, center=(0.5, 0.5, 0)))

# Adding labels one at a time
points = [[0, 0, 0], [1, 0, 0], [0, 1, 0], [1, 1, 0], [0.5, 0.5, 0.5]]
labels = ['A', 'B', 'C', 'D', 'E']

for i, (pt, lbl) in enumerate(zip(points, labels)):
    # Create PolyData for each point
    point_cloud = pv.PolyData([pt])
    pl.add_point_labels(point_cloud, [lbl], font_size=20, point_size=10, bold=True)

print(f"Total actors in scene: {len(pl.actors)}")

pl.show()

In summary, the outcome of my debugging is that:

  • (simple version) the labels are getting garbage collected at some point and pyvista loses this context.
  • (more complicated version) this has to do with how PyVista stores the labels in memory.

The simple solution is just to hold a reference to the labels like I have done in this PR.

@github-actions github-actions bot added the bug Something isn't working label Feb 17, 2026
@moe-ad moe-ad self-assigned this Feb 17, 2026
Copy link
Collaborator

@AlejandroFernandezLuces AlejandroFernandezLuces left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird error.. thanks for fixing it 🙂

@AlejandroFernandezLuces AlejandroFernandezLuces merged commit 311efc9 into main Feb 18, 2026
23 checks passed
@AlejandroFernandezLuces AlejandroFernandezLuces deleted the fix/labeling-visibility-issue branch February 18, 2026 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants