回答編集履歴
5
リファクタリング
test
CHANGED
@@ -42,19 +42,15 @@
|
|
42
42
|
|
43
43
|
self.ax1 = fig.add_axes([0.1, 0.1, 0.8, 0.8])
|
44
44
|
|
45
|
+
self.ax1.figure.canvas.mpl_connect('button_press_event', self.on_click)
|
46
|
+
|
47
|
+
self.ax1.figure.canvas.mpl_connect('key_press_event', self.on_key)
|
48
|
+
|
45
49
|
self.x = []
|
46
50
|
|
47
51
|
self.y = []
|
48
52
|
|
49
|
-
self.ax1.figure.canvas.mpl_connect('button_press_event', self.on_click)
|
50
|
-
|
51
|
-
self.ax1.figure.canvas.mpl_connect('key_press_event', self.on_key)
|
52
|
-
|
53
|
-
self.ax1.set_xticks(np.linspace(0, 4, 5))
|
54
|
-
|
55
|
-
self.ax1.set_yticks(np.linspace(0, 4, 5))
|
56
|
-
|
57
|
-
self.a
|
53
|
+
self.update_plot()
|
58
54
|
|
59
55
|
plt.show()
|
60
56
|
|
4
点の個数の表示を修正
test
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
|
11
|
+
(クリック点の描画をscatterにすると、spline曲線の更新と両立するうまいやり方がわからなかったので、下記コードでは、plot(x, y, 'ro')で代用しています)
|
12
12
|
|
13
13
|
|
14
14
|
|
@@ -94,7 +94,7 @@
|
|
94
94
|
|
95
95
|
return
|
96
96
|
|
97
|
-
# 過去の
|
97
|
+
# 過去の座標と同一座標をクリックした場合は抜ける
|
98
98
|
|
99
99
|
if event.xdata in self.x and event.ydata in self.y:
|
100
100
|
|
@@ -108,7 +108,7 @@
|
|
108
108
|
|
109
109
|
print('Added no.{} point at [{} {}]'.format(
|
110
110
|
|
111
|
-
len(self.x)
|
111
|
+
len(self.x), self.x[-1], self.y[-1]))
|
112
112
|
|
113
113
|
elif event.button == 3:
|
114
114
|
|
@@ -122,7 +122,7 @@
|
|
122
122
|
|
123
123
|
self.redraw()
|
124
124
|
|
125
|
-
print('Removed no.{0} point'.format(len(self.x)))
|
125
|
+
print('Removed no.{0} point'.format(len(self.x)+1))
|
126
126
|
|
127
127
|
|
128
128
|
|
@@ -130,27 +130,29 @@
|
|
130
130
|
|
131
131
|
self.ax1.cla()
|
132
132
|
|
133
|
+
count = len(self.x)
|
134
|
+
|
133
|
-
if
|
135
|
+
if count > 0:
|
134
136
|
|
135
137
|
# クリック点の描画
|
136
138
|
|
137
139
|
self.ax1.plot(self.x, self.y, 'ro')
|
138
140
|
|
139
|
-
if
|
141
|
+
if count <= 1:
|
140
142
|
|
141
143
|
self.update_plot()
|
142
144
|
|
143
145
|
return
|
144
146
|
|
145
|
-
|
147
|
+
if count == 2:
|
146
148
|
|
147
149
|
deg = 1
|
148
150
|
|
149
|
-
elif
|
151
|
+
elif count == 3:
|
150
152
|
|
151
153
|
deg = 2
|
152
154
|
|
153
|
-
elif
|
155
|
+
elif count > 3:
|
154
156
|
|
155
157
|
deg = 3
|
156
158
|
|
3
修正
test
CHANGED
@@ -9,10 +9,6 @@
|
|
9
9
|
|
10
10
|
|
11
11
|
下記コードでは、クリック点の描画をscatterにしたとき、spline曲線の更新と両立するうまいやり方がわからなかったので、plot(x, y, 'ro')で代用しています。
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
(部分的にリファクタリングしています)
|
16
12
|
|
17
13
|
|
18
14
|
|
2
過去のクリック点と同一の場所をクリックしてもエラーが発生しないようにした
test
CHANGED
@@ -98,13 +98,21 @@
|
|
98
98
|
|
99
99
|
return
|
100
100
|
|
101
|
+
# 過去のコントロール点と同一座標をクリックした場合は返る
|
102
|
+
|
103
|
+
if event.xdata in self.x and event.ydata in self.y:
|
104
|
+
|
105
|
+
return
|
106
|
+
|
101
107
|
self.x.append(event.xdata)
|
102
108
|
|
103
109
|
self.y.append(event.ydata)
|
104
110
|
|
105
111
|
self.redraw()
|
106
112
|
|
107
|
-
print('Added no.{} point at [{} {}]'.format(
|
113
|
+
print('Added no.{} point at [{} {}]'.format(
|
114
|
+
|
115
|
+
len(self.x)-1, self.x[-1], self.y[-1]))
|
108
116
|
|
109
117
|
elif event.button == 3:
|
110
118
|
|
1
リンク修正
test
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
-
[このページ](https://qiita.com/skotaro/items/08dc0b8c5704c94eafb9)の冒頭がわかりやすいかもしれません。
|
7
|
+
[このページ](https://qiita.com/skotaro/items/08dc0b8c5704c94eafb9)の冒頭に書いてある[ここ](https://qiita.com/skotaro/items/08dc0b8c5704c94eafb9#matplotlib%E3%81%AB%E3%81%AF%E3%82%B0%E3%83%A9%E3%83%95%E3%82%92%E4%BD%9C%E3%82%8B%E9%9A%9B%E3%81%AE%E4%BA%8C%E3%81%A4%E3%81%AE%E6%B5%81%E5%84%80%E3%81%8C%E3%81%82%E3%82%8B)がわかりやすいかもしれません。
|
8
8
|
|
9
9
|
|
10
10
|
|