Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legend not shown #2

Open
danieljuschus opened this issue Nov 2, 2022 · 2 comments
Open

Legend not shown #2

danieljuschus opened this issue Nov 2, 2022 · 2 comments

Comments

@danieljuschus
Copy link

danieljuschus commented Nov 2, 2022

Adding a legend by making the following changes to the usage example doesn't work, i.e. no legend is visible:

...
## Add mesh to the plotter
plotter.add_mesh(mesh, scalars='myscalar', cmap='bwr', line_width=1, label="cube")
plotter.add_legend()
...

No errors are being shown.

On the other hand, when calling plotter.show() before st.session_state.model = HTML_stpyvista(plotter), the legend is visible in the separate pyvista window:

image

@edsaac
Copy link
Owner

edsaac commented Nov 2, 2022

stpyvista uses the pythreejs backend to convert the pyvista plotter into an HTML that is then passed to streamlit. This has some limitations, like adding a colorbar or text (check https://docs.pyvista.org/user-guide/jupyter/pythreejs.html#caveats). When plotter.show() opens a new window, this means that pyvista is using a "standard desktop VTK render window" (https://docs.pyvista.org/user-guide/jupyter/index.html#usage-with-pyvista).

I'll try checking if there is a workaround, as threejs does support labels (e.g., https://threejs.org/examples/css2d_label).

@edsaac
Copy link
Owner

edsaac commented Mar 30, 2023

With the panel backend (from stpyvista>=0.0.7), colorbars and titles can be added to the plotter. They are not totally legends, but can serve as a way to annotate stuff in the plotter.

image

## Add mesh to the plotter
plotter.add_mesh(mesh, cmap='bwr', line_width=1,)
plotter.add_scalar_bar()
plotter.add_title("My cube", color="black", font_size=14)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants