質問編集履歴
2
文法の更新
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,19 +28,9 @@
|
|
28
28
|
|
29
29
|
```python
|
30
30
|
|
31
|
-
#!/usr/bin/env python3
|
32
|
-
|
33
|
-
# -*- coding: utf-8 -*-
|
34
|
-
|
35
|
-
"""
|
36
|
-
|
37
|
-
Created on Fri Jul 30 16:00:20 2021
|
38
31
|
|
39
32
|
|
40
33
|
|
41
|
-
@author: ryotsu
|
42
|
-
|
43
|
-
"""
|
44
34
|
|
45
35
|
|
46
36
|
|
@@ -182,7 +172,7 @@
|
|
182
172
|
|
183
173
|
|
184
174
|
|
185
|
-
igureCanvasTkAggにて作成を試みたができなかった
|
175
|
+
FigureCanvasTkAggにて作成を試みたができなかった
|
186
176
|
|
187
177
|
|
188
178
|
|
@@ -190,4 +180,4 @@
|
|
190
180
|
|
191
181
|
|
192
182
|
|
193
|
-
|
183
|
+
Python 初心者ですがよろしくお願い致します.
|
1
コードの更新
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,21 +28,37 @@
|
|
28
28
|
|
29
29
|
```python
|
30
30
|
|
31
|
+
#!/usr/bin/env python3
|
32
|
+
|
33
|
+
# -*- coding: utf-8 -*-
|
34
|
+
|
35
|
+
"""
|
36
|
+
|
37
|
+
Created on Fri Jul 30 16:00:20 2021
|
31
38
|
|
32
39
|
|
40
|
+
|
33
|
-
|
41
|
+
@author: ryotsu
|
42
|
+
|
43
|
+
"""
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
34
48
|
|
35
49
|
import numpy as np
|
36
50
|
|
37
51
|
import matplotlib.pyplot as plt
|
38
52
|
|
39
|
-
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
|
53
|
+
from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg, NavigationToolbar2Tk)
|
40
54
|
|
41
55
|
import tkinter as tk
|
42
56
|
|
43
57
|
import tkinter.ttk as ttk
|
44
58
|
|
45
59
|
from matplotlib.figure import Figure
|
60
|
+
|
61
|
+
from matplotlib.backend_bases import key_press_handler
|
46
62
|
|
47
63
|
|
48
64
|
|
@@ -80,47 +96,83 @@
|
|
80
96
|
|
81
97
|
l = float (txt.get())
|
82
98
|
|
83
|
-
|
99
|
+
print (l)
|
84
100
|
|
85
101
|
|
86
102
|
|
87
|
-
x = np.arange(0,
|
103
|
+
x = np.arange(0, 1, 0.001)
|
88
104
|
|
89
105
|
y1 = np.sin(l*x)
|
90
106
|
|
91
107
|
y2 = np.cos(l*x)
|
92
108
|
|
93
|
-
plt.subplot(211)
|
94
109
|
|
95
|
-
plt.plot(x,y1)
|
96
110
|
|
97
|
-
|
111
|
+
fig1 = Figure(figsize=(5, 4), dpi=100)
|
98
112
|
|
99
|
-
|
113
|
+
fig2 = Figure(figsize=(5, 4), dpi=100)
|
100
114
|
|
101
|
-
|
115
|
+
|
102
116
|
|
103
|
-
|
117
|
+
fig1.add_subplot().plot(x, y1)
|
104
118
|
|
105
|
-
plt.plot(x,y2)
|
119
|
+
fig2.add_subplot().plot(x, y2)
|
106
|
-
|
107
|
-
plt.xlabel("x")
|
108
|
-
|
109
|
-
plt.ylabel("y2")
|
110
|
-
|
111
|
-
plt.tight_layout()
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
plt.show()
|
116
120
|
|
117
121
|
|
118
122
|
|
123
|
+
|
124
|
+
|
125
|
+
canvas1 = FigureCanvasTkAgg(fig1, master=root)
|
126
|
+
|
127
|
+
canvas2 = FigureCanvasTkAgg(fig2, master=root)# A tk.DrawingArea.
|
128
|
+
|
129
|
+
canvas1.draw()
|
130
|
+
|
131
|
+
canvas2.draw()
|
132
|
+
|
133
|
+
toolbar1 = NavigationToolbar2Tk(canvas1, root, pack_toolbar=False)
|
134
|
+
|
135
|
+
toolbar1.update()
|
136
|
+
|
137
|
+
toolbar2 = NavigationToolbar2Tk(canvas2, root, pack_toolbar=False)
|
138
|
+
|
139
|
+
toolbar2.update()
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
canvas1.mpl_connect(
|
144
|
+
|
145
|
+
"key_press_event", lambda event: print(f"you pressed {event.key}"))
|
146
|
+
|
147
|
+
canvas1.mpl_connect("key_press_event", key_press_handler)
|
148
|
+
|
119
149
|
|
150
|
+
|
151
|
+
canvas1.mpl_connect(
|
152
|
+
|
153
|
+
"key_press_event", lambda event: print(f"you pressed {event.key}"))
|
154
|
+
|
155
|
+
canvas1.mpl_connect("key_press_event", key_press_handler)
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
button = tk.Button(master=root, text="Quit", command=root.quit)
|
160
|
+
|
161
|
+
btn_1["command"] = btn_1_click
|
162
|
+
|
163
|
+
|
120
164
|
|
121
165
|
|
122
166
|
|
123
167
|
root.mainloop()
|
168
|
+
|
169
|
+
```
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
|
124
176
|
|
125
177
|
```
|
126
178
|
|