回答編集履歴
1
右クリック版追加
test
CHANGED
@@ -66,6 +66,64 @@
|
|
66
66
|
|
67
67
|
plt.show()
|
68
68
|
|
69
|
+
```
|
70
|
+
|
71
|
+
右クリック版追加しておきます。
|
72
|
+
|
73
|
+
```Python
|
74
|
+
|
75
|
+
import matplotlib.pyplot as plt
|
76
|
+
|
77
|
+
plt.rcParams['font.family'] = 'MS Gothic'
|
78
|
+
|
79
|
+
markers = list('ov^<>12348sp*hH+xD')
|
80
|
+
|
81
|
+
colors = list('bgrcmyk')
|
82
|
+
|
83
|
+
dots = []
|
84
|
+
|
85
|
+
def motion(event):
|
86
|
+
|
87
|
+
global i, j, cnt
|
88
|
+
|
89
|
+
if event.button == 3: # 右クリック
|
90
|
+
|
91
|
+
if dots and cnt > 0:
|
92
|
+
|
93
|
+
dots.pop().remove()
|
94
|
+
|
95
|
+
cnt -= 1
|
96
|
+
|
97
|
+
else:
|
98
|
+
|
99
|
+
x, y = event.xdata, event.ydata
|
100
|
+
|
101
|
+
dot, = plt.plot([x], [y], color=colors[j], marker=markers[i], markersize=12)
|
102
|
+
|
103
|
+
dots.append(dot)
|
104
|
+
|
105
|
+
i, j = (i + 1) % len(markers), (j + 1) % len(colors)
|
106
|
+
|
107
|
+
cnt += 1
|
108
|
+
|
109
|
+
leg = plt.legend([f'クリック回数 {cnt}'], markerscale=0, handletextpad=-2.0, loc='upper right')
|
110
|
+
|
111
|
+
if leg.legendHandles:
|
112
|
+
|
113
|
+
leg.legendHandles[0].set_visible(False)
|
114
|
+
|
115
|
+
plt.draw()
|
69
116
|
|
70
117
|
|
118
|
+
|
119
|
+
plt.xlim(0, 1)
|
120
|
+
|
121
|
+
plt.ylim(0, 1)
|
122
|
+
|
123
|
+
i = j = cnt = 0
|
124
|
+
|
125
|
+
plt.connect('button_press_event', motion)
|
126
|
+
|
127
|
+
plt.show()
|
128
|
+
|
71
129
|
```
|