Skip to content

Instantly share code, notes, and snippets.

@MBulli
Created February 21, 2023 12:29
Show Gist options
  • Save MBulli/dcb2eb07c5bdc84f58ff466de96a7c06 to your computer and use it in GitHub Desktop.
Save MBulli/dcb2eb07c5bdc84f58ff466de96a7c06 to your computer and use it in GitHub Desktop.
import typing
from pathlib import Path
import plotly.graph_objects as go
def plotly_get_top_view_camera() -> go.layout.scene.Camera:
return go.layout.scene.Camera(
projection=go.layout.scene.camera.Projection(type='orthographic'),
up=dict(x=0, y=1, z=0),
center=dict(x=0, y=0, z=0),
eye=dict(x=0, y=0, z=2)
)
def plotly_set_top_view(fig: go.Figure) -> go.Figure:
topCam = plotly_get_top_view_camera()
fig.update_scenes(camera=topCam)
return fig
def plotly_scale_y_equal_to_x(fig: go.Figure, scaleratio=1) -> go.Figure:
fig.update_yaxes(
scaleanchor="x",
scaleratio=scaleratio,
)
return fig
def plotly_writeHtml(fig: typing.Optional[go.Figure], outputPath: Path):
if fig is not None:
outputPath.parent.mkdir(parents=True, exist_ok=True)
fig.write_html(file=outputPath, include_plotlyjs='cdn')
def plotly_writePng(fig: typing.Optional[go.Figure], outputPath: Path):
if fig is not None:
outputPath.parent.mkdir(parents=True, exist_ok=True)
fig.write_image(file=outputPath, scale=2.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment