-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support batch axes + broadcasting for
viser.transforms
(#208)
* Support batch axes + broadcasting for `viser.transforms` * Nits * Sync docs * Fix type
- Loading branch information
Showing
14 changed files
with
587 additions
and
356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
.. Comment: this file is automatically generated by `update_example_docs.py`. | ||
It should not be modified manually. | ||
Plotly. | ||
========================================== | ||
|
||
|
||
Examples of visualizing plotly plots in Viser. | ||
|
||
|
||
|
||
.. code-block:: python | ||
:linenos: | ||
import time | ||
import numpy as onp | ||
import plotly.express as px | ||
import plotly.graph_objects as go | ||
import viser | ||
from PIL import Image | ||
def create_sinusoidal_wave(t: float) -> go.Figure: | ||
"""Create a sinusoidal wave plot, starting at time t.""" | ||
x_data = onp.linspace(t, t + 6 * onp.pi, 50) | ||
y_data = onp.sin(x_data) * 10 | ||
fig = px.line( | ||
x=list(x_data), | ||
y=list(y_data), | ||
labels={"x": "x", "y": "sin(x)"}, | ||
title="Sinusoidal Wave", | ||
) | ||
# this sets the margins to be tight around the title. | ||
fig.layout.title.automargin = True # type: ignore | ||
fig.update_layout( | ||
margin=dict(l=20, r=20, t=20, b=20), | ||
) # Reduce plot margins. | ||
return fig | ||
def main() -> None: | ||
server = viser.ViserServer() | ||
# Plot type 1: Line plot. | ||
line_plot_time = 0.0 | ||
line_plot = server.add_gui_plotly(figure=create_sinusoidal_wave(line_plot_time)) | ||
# Plot type 2: Image plot. | ||
fig = px.imshow(Image.open("assets/Cal_logo.png")) | ||
fig.update_layout( | ||
margin=dict(l=20, r=20, t=20, b=20), | ||
) | ||
server.add_gui_plotly(figure=fig, aspect=1.0) | ||
# Plot type 3: 3D Scatter plot. | ||
fig = px.scatter_3d( | ||
px.data.iris(), | ||
x="sepal_length", | ||
y="sepal_width", | ||
z="petal_width", | ||
color="species", | ||
) | ||
fig.update_layout(legend=dict(yanchor="top", y=0.99, xanchor="left", x=0.01)) | ||
fig.update_layout( | ||
margin=dict(l=20, r=20, t=20, b=20), | ||
) | ||
server.add_gui_plotly(figure=fig, aspect=1.0) | ||
while True: | ||
# Update the line plot. | ||
line_plot_time += 0.1 | ||
line_plot.figure = create_sinusoidal_wave(line_plot_time) | ||
time.sleep(0.01) | ||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.