forked from awesome-panel/awesome-panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
41 lines (30 loc) · 1.03 KB
/
script.py
File metadata and controls
41 lines (30 loc) · 1.03 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
import matplotlib.pyplot as plt
import numpy as np
import panel as pn
from matplotlib import cm
from matplotlib.figure import Figure
pn.extension(template="fast")
def get_theme() -> str:
"""Returns the name of the active theme"""
template = pn.state.template
theme = "dark" if template.theme == pn.template.DarkTheme else "default"
return theme
def get_plot(theme="default"):
plt.style.use("default")
if theme == "dark":
plt.style.use("dark_background")
Y, X = np.mgrid[-3:3:100j, -3:3:100j]
U = -1 - X**2 + Y
V = 1 + X - Y**2
fig0 = Figure(figsize=(12, 6))
ax0 = fig0.subplots()
strm = ax0.streamplot(X, Y, U, V, color=U, linewidth=2, cmap=cm.autumn)
fig0.colorbar(strm.lines)
return fig0
plot = get_plot(theme=get_theme())
pn.pane.Matplotlib(plot, height=600, sizing_mode="scale_height", align="center").servable()
pn.Column(
pn.Spacer(),
pn.pane.Matplotlib(plot, height=600, sizing_mode="scale_height", align="center"),
sizing_mode="stretch_both",
).servable()