-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrapper.py
More file actions
46 lines (41 loc) · 1.14 KB
/
wrapper.py
File metadata and controls
46 lines (41 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import plotly.io as pio
import sys
import os
# Inject user code at the root level (no indentation required)
{{SOURCE}}
# Internal Plotly Handling
try:
if 'fig' in locals():
# Get user height or default to 450
local_height = locals().get('plot_height', 450)
fig.update_layout(
height=local_height,
paper_bgcolor='rgba(0,0,0,0)',
plot_bgcolor='rgba(0,0,0,0)',
font=dict(color='{{TEXT_COLOR}}'),
xaxis=dict(
gridcolor='{{TEXT_COLOR}}',
zerolinecolor='{{TEXT_COLOR}}',
showgrid=True
),
yaxis=dict(
gridcolor='{{TEXT_COLOR}}',
zerolinecolor='{{TEXT_COLOR}}',
showgrid=True
),
margin=dict(l=20, r=20, t=60, b=20),
template="none"
)
pio.write_html(
fig,
file=r'{{HTML_PATH}}', # use raw string to handle backslashes in paths
auto_open=False,
full_html=True,
include_plotlyjs='cdn'
)
print("Plot success!")
else:
sys.stderr.write("No 'fig' object found. Ensure your script defines 'fig'.")
except Exception as e:
print(f"Plotly Error: {str(e)}")
sys.stderr.write(f"Plotly Error: {str(e)}")