Created
February 21, 2023 12:29
-
-
Save MBulli/dcb2eb07c5bdc84f58ff466de96a7c06 to your computer and use it in GitHub Desktop.
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
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