-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipympl_demo.py
More file actions
46 lines (32 loc) · 1.14 KB
/
Copy pathipympl_demo.py
File metadata and controls
46 lines (32 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
"""Window-mode demo: interactive Matplotlib via ipympl in a Tk pop-up.
Requires:
pip install -e ".[demo]"
Run:
python examples/ipympl_demo.py
``import ipympl`` (after the App exists, and preferably after matplotlib) opts
into the interactive WebView backend. Plain Matplotlib demos omit that import
and keep PNG / TkAgg.
"""
from __future__ import annotations
import numpy as np
from tkipw import App, display
def main() -> None:
# Host root is withdrawn; the live ipympl canvas opens in a pop-up.
app = App(title="tkipw · ipympl", display_mode="window")
# Load matplotlib first, then ipympl (matches ipympl's own ``use()`` path
# and the App import hook).
import importlib
plt = importlib.import_module("matplotlib.pyplot")
importlib.import_module("ipympl")
fig, ax = plt.subplots(figsize=(6.4, 3.6), dpi=100)
x = np.linspace(0, 2 * np.pi, 200)
ax.plot(x, np.sin(x), color="#2563eb", lw=2)
ax.set_title("ipympl in tkipw")
ax.set_xlabel("x")
ax.set_ylabel("sin(x)")
ax.grid(True, alpha=0.3)
fig.tight_layout()
display(fig.canvas)
app.run()
if __name__ == "__main__":
main()