回答編集履歴
2
修正
answer
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
公式の[Keypress Demo](https://matplotlib.org/3.1.0/gallery/event_handling/keypress_demo.html)が参考になります。
|
2
|
-
以下は入力されたキー値をxラベルとして表示する例です。
|
2
|
+
以下は入力されたキー値をxラベルとグラフ内のtextとして表示する例です。
|
3
3
|
```Python
|
4
4
|
import sys
|
5
5
|
import matplotlib.pyplot as plt
|
1
コード修正
answer
CHANGED
@@ -7,6 +7,7 @@
|
|
7
7
|
def press(event):
|
8
8
|
print(event.key)
|
9
9
|
ax.set_xlabel(event.key)
|
10
|
+
txt.set_text(event.key)
|
10
11
|
plt.draw()
|
11
12
|
|
12
13
|
fig, ax = plt.subplots()
|
@@ -14,5 +15,6 @@
|
|
14
15
|
|
15
16
|
ax.plot([1], [1], 'go')
|
16
17
|
ax.set_title('Press a key')
|
18
|
+
txt = ax.text(1,1,'', fontsize=24)
|
17
19
|
plt.show()
|
18
20
|
```
|