teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

文法の更新

2021/08/01 16:43

投稿

5555maru
5555maru

スコア1

title CHANGED
File without changes
body CHANGED
@@ -13,15 +13,10 @@
13
13
  ### 該当のソースコード
14
14
 
15
15
  ```python
16
- #!/usr/bin/env python3
17
- # -*- coding: utf-8 -*-
18
- """
19
- Created on Fri Jul 30 16:00:20 2021
20
16
 
21
- @author: ryotsu
22
- """
23
17
 
24
18
 
19
+
25
20
  import numpy as np
26
21
  import matplotlib.pyplot as plt
27
22
  from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg, NavigationToolbar2Tk)
@@ -90,8 +85,8 @@
90
85
 
91
86
  ### 試したこと
92
87
 
93
- igureCanvasTkAggにて作成を試みたができなかった
88
+ FigureCanvasTkAggにて作成を試みたができなかった
94
89
 
95
90
  ### 補足情報(FW/ツールのバージョンなど)
96
91
 
97
- ここにり詳細な情報を記載ださ
92
+ Python 初心者ですがしくお願致します.

1

コードの更新

2021/08/01 16:43

投稿

5555maru
5555maru

スコア1

title CHANGED
File without changes
body CHANGED
@@ -13,14 +13,22 @@
13
13
  ### 該当のソースコード
14
14
 
15
15
  ```python
16
+ #!/usr/bin/env python3
17
+ # -*- coding: utf-8 -*-
18
+ """
19
+ Created on Fri Jul 30 16:00:20 2021
16
20
 
17
- ```
21
+ @author: ryotsu
22
+ """
23
+
24
+
18
25
  import numpy as np
19
26
  import matplotlib.pyplot as plt
20
- from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
27
+ from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg, NavigationToolbar2Tk)
21
28
  import tkinter as tk
22
29
  import tkinter.ttk as ttk
23
30
  from matplotlib.figure import Figure
31
+ from matplotlib.backend_bases import key_press_handler
24
32
 
25
33
 
26
34
 
@@ -39,29 +47,47 @@
39
47
  def btn_1_click():
40
48
 
41
49
  l = float (txt.get())
50
+ print (l)
42
51
 
43
-
44
- x = np.arange(0, 6, 0.1)
52
+ x = np.arange(0, 1, 0.001)
45
53
  y1 = np.sin(l*x)
46
54
  y2 = np.cos(l*x)
55
+
47
- plt.subplot(211)
56
+ fig1 = Figure(figsize=(5, 4), dpi=100)
57
+ fig2 = Figure(figsize=(5, 4), dpi=100)
58
+
48
- plt.plot(x,y1)
59
+ fig1.add_subplot().plot(x, y1)
49
- plt.xlabel("x")
50
- plt.ylabel("y1")
51
-
52
- plt.subplot(212)
53
- plt.plot(x,y2)
60
+ fig2.add_subplot().plot(x, y2)
54
- plt.xlabel("x")
55
- plt.ylabel("y2")
56
- plt.tight_layout()
57
-
58
- plt.show()
59
61
 
62
+
63
+ canvas1 = FigureCanvasTkAgg(fig1, master=root)
64
+ canvas2 = FigureCanvasTkAgg(fig2, master=root)# A tk.DrawingArea.
65
+ canvas1.draw()
66
+ canvas2.draw()
67
+ toolbar1 = NavigationToolbar2Tk(canvas1, root, pack_toolbar=False)
68
+ toolbar1.update()
69
+ toolbar2 = NavigationToolbar2Tk(canvas2, root, pack_toolbar=False)
70
+ toolbar2.update()
71
+
72
+ canvas1.mpl_connect(
73
+ "key_press_event", lambda event: print(f"you pressed {event.key}"))
74
+ canvas1.mpl_connect("key_press_event", key_press_handler)
60
75
 
76
+ canvas1.mpl_connect(
77
+ "key_press_event", lambda event: print(f"you pressed {event.key}"))
78
+ canvas1.mpl_connect("key_press_event", key_press_handler)
61
79
 
80
+ button = tk.Button(master=root, text="Quit", command=root.quit)
81
+ btn_1["command"] = btn_1_click
82
+
83
+
62
84
  root.mainloop()
63
85
  ```
64
86
 
87
+
88
+
89
+ ```
90
+
65
91
  ### 試したこと
66
92
 
67
93
  igureCanvasTkAggにて作成を試みたができなかった