質問編集履歴

7

必要な部分だけにした

2018/07/17 06:41

投稿

yamatail
yamatail

スコア77

test CHANGED
@@ -1 +1 @@
1
- wxpythonでmatplotlibを用いた2次元ラフをボタンとコンックスで切り替えて表示させたい。
1
+ wxpython】コンボボックスとトボタンの値をテキストボックス表示させたい。
test CHANGED
@@ -2,107 +2,21 @@
2
2
 
3
3
 
4
4
 
5
- 3次元データ[データ番号,x軸,y軸]を扱うGUI作中です。
5
+ wxpythonでGUiを作中です。
6
-
7
- リストは3つ作っています。
8
-
9
- ScanList = [["番号","データタイトル"],...]
10
-
11
- ScanDet = [["x軸","y軸"],...]
12
-
13
- ScanData = グラフに用いるデータ[x軸,y軸,スキャン番号]の三次元配列
14
6
 
15
7
 
16
8
 
17
- 以下、ード
9
+ GUIにはンボボックスとトグルボタンとStaticTextを配置しました。
18
10
 
19
11
 
20
12
 
21
- ```python
13
+ コンボボックスでOntextイベントを行う際
22
14
 
23
- ScanList = [["scan : 1","data 2018/07/05 13:00"],["scan : 2","data 2018/07/05 14:00"],["scan : 3","data 2018/07/05 15:00"]]
24
-
25
- ScanDet = [["xaxis_1","yaxis_1"],["xaxis_2","yaxis_2"],["xaxis_3","yaxis_3"]]
26
-
27
- ScanData = [[[1,1],[2,2],[3,3],[4,4]],[[1,1],[2,4],[3,9],[4,16]],[[1,1],[2,0.5],[3,0.3],[4,0.25]]]
28
-
29
- ```
30
-
31
- 製作中のGUIは、データ番号をコンボボックスで選びながら2次元ラフを表示させるものです。
15
+ コンボボックス内のテキストと同時にトルボタンのステータス(TRUE or FALSE)も取得させたいです。
32
16
 
33
17
 
34
18
 
35
- コンボボックスのGetSelection()でステータスをとり、3つのデータのindexで紐つけし、必要なデータをそれぞれ抽出しグラフを描くようにしております。
36
-
37
- そして必要に応じて
38
-
39
- トグルボタンでy軸のline/logスケールを切り替え出来るようにしたいのです。
40
-
41
- ![イメージ説明](9c0b9db8817e524080ae97a3feec5712.png)
42
-
43
- イメージは、
44
-
45
-
46
-
47
- コンボボックスでホイールをころころする
48
-
49
- 選択されたデータのグラフが表示される ⇒ これは実現済み
50
-
51
-
52
-
53
- 次にトグルボタンでlogを選択する
54
-
55
- コンボボックスでホイールをころころする
56
-
57
- 選択されたデータのグラフがLogで表示される ⇒ ここで引っかかっています
58
-
59
-
60
-
61
-
62
-
63
- まだまだpythonの階層構造自体知識が不十分なため難儀しております。
64
-
65
-
66
-
67
- コードの書き方等で「そもそも・・・」というお話もあるかと思いますので、
68
-
69
- 何でもよいので、ご教授頂けると大変助かります。
70
-
71
-
72
-
73
- ### 発生している問題・エラーメッセージ
74
-
75
-
76
-
77
- コンボボックスで2次元グラフを表示させるところまではいきました。
78
-
79
- が、line/log切り替え機能がうまく合わさりません。
80
-
81
-
82
-
83
- logに切り替えると
84
-
85
- AttributeError:'MainFrame' object has no attribute 'combobox_1'
86
-
87
- とエラをはきます。
19
+ 以下、コドになります。
88
-
89
-
90
-
91
- Ontext()メソッドのなかで
92
-
93
- ToggleButton.GetValue()が取れれば下の様なコードを挟めて良いのかなと思ったりするのですが、うまくいきません。
94
-
95
-
96
-
97
- if self.button_1.GetValuen == True:
98
-
99
- self.plot.set_yscale('log')
100
-
101
-
102
-
103
-
104
-
105
- ### 該当のソースコード
106
20
 
107
21
 
108
22
 
@@ -110,21 +24,7 @@
110
24
 
111
25
  import wx
112
26
 
113
- import numpy as np
114
-
115
-
116
-
117
- import matplotlib
27
+ import os
118
-
119
- matplotlib.interactive( True )
120
-
121
- matplotlib.use( 'WXAgg' )
122
-
123
- import matplotlib.pyplot as plt
124
-
125
- from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
126
-
127
- from matplotlib.figure import Figure
128
28
 
129
29
 
130
30
 
@@ -134,35 +34,17 @@
134
34
 
135
35
  def __init__(self):
136
36
 
137
- wx.Frame.__init__(self, None, wx.ID_ANY, 'logplot', size = (1000, 800))
37
+ wx.Frame.__init__(self, None, wx.ID_ANY, 'logplot')
138
38
 
139
39
  panel = wx.Panel(self, wx.ID_ANY)
140
40
 
141
41
  panel.SetBackgroundColour(wx.Colour(128, 128, 128))
142
42
 
143
- plt.style.use('bmh')
144
-
145
- #matplotlib figure
146
-
147
- figure = matplotlib.figure.Figure()
148
-
149
- figure.subplots_adjust(left=0.075, bottom=0.1, right=0.95, top=0.95, wspace=0.15, hspace=0.15)
150
-
151
- self.plot = figure.add_subplot( 111 ,xlabel = 'X', ylabel = 'y')
152
-
153
- #canvas
154
-
155
- self.canvas = FigureCanvasWxAgg(panel, wx.ID_ANY, figure)
156
-
157
- self.canvas.SetBackgroundColour( wx.Colour( 100, 255, 255 ))
158
-
159
43
 
160
44
 
161
45
  #combobox
162
46
 
163
- element_array = [row[0] for row in ScanList]
164
-
165
- combobox_1 = wx.ComboBox(panel, wx.ID_ANY, 'select ScanList', choices = element_array, style = wx.CB_READONLY)
47
+ combobox_1 = wx.ComboBox(panel, wx.ID_ANY, 'select ScanList', choices = ("1","2","3"), style = wx.CB_READONLY)
166
48
 
167
49
  combobox_1.Bind(wx.EVT_TEXT, self.Ontext)
168
50
 
@@ -170,117 +52,81 @@
170
52
 
171
53
  #button
172
54
 
173
- button_1 = wx.ToggleButton(panel, wx.ID_ANY, 'Log', size = ( 60, -1) )
55
+ button_1 = wx.ToggleButton(panel, wx.ID_ANY, 'Line/Log')
174
56
 
175
- button_1.Bind(wx.EVT_TOGGLEBUTTON, self.click_button_1)
57
+ button_1.Bind(wx.EVT_TOGGLEBUTTON, self.button_click)
176
58
 
59
+
177
60
 
61
+ #Text
62
+
63
+ text_1 = wx.StaticText(panel, wx.ID_ANY, )
64
+
65
+
178
66
 
179
67
  vbox_1 = wx.BoxSizer(wx.VERTICAL)
180
68
 
181
- hbox_1 = wx.BoxSizer(wx.HORIZONTAL)
69
+ vbox_1.Add(combobox_1, 0, wx.LEFT | wx.RIGHT, 10)
182
70
 
183
- hbox_1.Add(combobox_1, wx.ALIGN_CENTER)
71
+ vbox_1.Add(button_1, 0, wx.RIGHT, 10)
184
72
 
185
- hbox_1.Add(button_1, wx.ALIGN_CENTER)
73
+ vbox_1.Add(text_1, 0, wx.RIGHT, 10)
186
74
 
187
- vbox_1.Add(hbox_1)
75
+
188
-
189
-
190
-
191
- vbox_1.Add((-1,10))
192
-
193
-
194
-
195
- vbox_1.Add(self.canvas, 1, wx.LEFT | wx.RIGHT |wx.EXPAND, 10)
196
-
197
-
198
76
 
199
77
  panel.SetSizer(vbox_1)
200
78
 
201
79
 
202
80
 
81
+ def button_click(self, event):
82
+
83
+ button_1 = event.GetEventObject()
84
+
85
+ if button_1.GetValue():
86
+
87
+ button_1.SetLabel("Log")
88
+
89
+ else:
90
+
91
+ button_1.SetLabel("Line")
92
+
93
+ print(button_1.GetValue())
94
+
95
+
96
+
203
97
  def Ontext(self, event):
204
98
 
205
- self.plot.clear()
99
+ #print(button_1.GetValue())
206
100
 
207
101
  combobox_1 = event.GetEventObject()
208
102
 
209
- button_1 = event.GetEventObject()
103
+ print(combobox_1.GetValue())
210
104
 
211
- drawdata = np.array(ScanData[combobox_1.GetSelection()])
105
+
212
-
213
- x = drawdata[:,0]
214
-
215
- y = drawdata[:,1]
216
-
217
- self.plot.plot(x, y, linestyle = "solid", marker = "o")
218
-
219
- axislabel = [row[0] for row in ScanDet]
220
-
221
- detlabel = [row[1] for row in ScanDet]
222
-
223
- self.plot.set_xlabel(axislabel[combobox_1.GetSelection()])
224
-
225
- self.plot.set_ylabel(detlabel[combobox_1.GetSelection()])
226
-
227
- self.plot.set_title(ScanList[combobox_1.GetSelection()][1])
228
-
229
- self.plot.grid(which = "major", color = "black", linestyle = "dashed")
230
-
231
- self.canvas.draw()
232
-
233
-
234
-
235
- def click_button_1(self, event):
236
-
237
- self.plot.clear()
238
-
239
- drawdata = np.array(ScanData[self.combobox_1.GetSelection])
240
-
241
- x = drawdata[:,0]
242
-
243
- y = drawdata[:,1]
244
-
245
- plt.xscale("log")
246
-
247
- self.plot.plot(x, y, linestyle = "solid", marker = "o")
248
-
249
- axislabel = [row[0] for row in ScanDet]
250
-
251
- detlabel = [row[1] for row in ScanDet]
252
-
253
- self.plot.set_xlabel(axislabel[combobox_1.GetSelection()])
254
-
255
- self.pldot.set_ylabel(detlabel[combobox_1.GetSelection()])
256
-
257
- self.plot.set_title(ScanList[combobox_1.GetSelection()][1])
258
-
259
- self.plot.grid(which = "major", color = "black", linestyle = "dashed")
260
-
261
- self.canvas.draw()
262
-
263
-
264
106
 
265
107
  if __name__ == '__main__':
266
-
267
- ScanList = [["scan : 1","data 2018/07/05 13:00"],["scan : 2","data 2018/07/05 14:00"],["scan : 3","data 2018/07/05 15:00"]]
268
-
269
- ScanDet = [["xaxis_1","yaxis_1"],["xaxis_2","yaxis_2"],["xaxis_3","yaxis_3"]]
270
-
271
- ScanData = [[[1,1],[2,2],[3,3],[4,4]],[[1,1],[2,4],[3,9],[4,16]],[[1,1],[2,0.5],[3,0.3],[4,0.25]]]
272
108
 
273
109
  app = wx.App()
274
110
 
275
111
  MainFrame().Show()
276
112
 
277
-
278
-
279
- ``````
113
+ app.MainLoop()
280
114
 
281
115
 
282
116
 
117
+
118
+
119
+ ```
120
+
283
- ### 試したこと
121
+ ###分からないこと
122
+
123
+ ・statictextにコンボボックスの値とトグルボタンの値を受け渡す方法
124
+
125
+ イメージは、Ontext()イベントでコンボボックスをマウスのホイールでころころするとその都度コンボボックスのテキスト値とトグルボタンの値を読み取って表示させることです。
126
+
127
+
128
+
129
+
284
130
 
285
131
 
286
132
 

6

表題を変更

2018/07/17 06:41

投稿

yamatail
yamatail

スコア77

test CHANGED
@@ -1 +1 @@
1
- 2次元グラフをボタンとコンボボックスで切り替えて表示させたい。
1
+ wxpythonでmatplotlibを用いた2次元グラフをボタンとコンボボックスで切り替えて表示させたい。
test CHANGED
File without changes

5

タグを追加

2018/07/09 04:56

投稿

yamatail
yamatail

スコア77

test CHANGED
File without changes
test CHANGED
File without changes

4

画像の添付

2018/07/09 04:52

投稿

yamatail
yamatail

スコア77

test CHANGED
File without changes
test CHANGED
@@ -30,14 +30,34 @@
30
30
 
31
31
  製作中のGUIは、データ番号をコンボボックスで選びながら2次元グラフを表示させるものです。
32
32
 
33
+
34
+
33
35
  コンボボックスのGetSelection()でステータスをとり、3つのデータのindexで紐つけし、必要なデータをそれぞれ抽出しグラフを描くようにしております。
34
36
 
35
-
36
-
37
37
  そして必要に応じて
38
38
 
39
39
  トグルボタンでy軸のline/logスケールを切り替え出来るようにしたいのです。
40
40
 
41
+ ![イメージ説明](9c0b9db8817e524080ae97a3feec5712.png)
42
+
43
+ イメージは、
44
+
45
+
46
+
47
+ コンボボックスでホイールをころころする
48
+
49
+ 選択されたデータのグラフが表示される ⇒ これは実現済み
50
+
51
+
52
+
53
+ 次にトグルボタンでlogを選択する
54
+
55
+ コンボボックスでホイールをころころする
56
+
57
+ 選択されたデータのグラフがLogで表示される ⇒ ここで引っかかっています
58
+
59
+
60
+
41
61
 
42
62
 
43
63
  まだまだpythonの階層構造自体知識が不十分なため難儀しております。

3

コードの変更

2018/07/09 03:01

投稿

yamatail
yamatail

スコア77

test CHANGED
File without changes
test CHANGED
@@ -4,15 +4,39 @@
4
4
 
5
5
  3次元データ[データ番号,x軸,y軸]を扱うGUIを製作中です。
6
6
 
7
+ リストは3つ作っています。
8
+
7
- といっても実際は、データ番号のリストとデータのリスは、別で設けてありindex等で紐つけしております。
9
+ ScanList = [["番号","データタイル"],...]
10
+
8
-
11
+ ScanDet = [["x軸","y軸"],...]
12
+
9
-
13
+ ScanData = グラフに用いるデータ[x軸,y軸,スキャン番号]の三次元配列
14
+
15
+
16
+
10
-
17
+ 以下、コード
18
+
19
+
20
+
21
+ ```python
22
+
23
+ ScanList = [["scan : 1","data 2018/07/05 13:00"],["scan : 2","data 2018/07/05 14:00"],["scan : 3","data 2018/07/05 15:00"]]
24
+
25
+ ScanDet = [["xaxis_1","yaxis_1"],["xaxis_2","yaxis_2"],["xaxis_3","yaxis_3"]]
26
+
27
+ ScanData = [[[1,1],[2,2],[3,3],[4,4]],[[1,1],[2,4],[3,9],[4,16]],[[1,1],[2,0.5],[3,0.3],[4,0.25]]]
28
+
29
+ ```
30
+
11
- 製作中のGUIは、データ番号を選びながら2次元グラフを表示させるものです。
31
+ 製作中のGUIは、データ番号をコンボボックスで選びながら2次元グラフを表示させるものです。
12
-
32
+
13
- コンボボックスのgetselection()を用いてデータ番号2次元データ紐つけしグラフを描くようにしております。
33
+ コンボボックスのGetSelection()でステータスをり、3つのデータのindexで紐つけし、必要なデータをそれぞれ抽出しグラフを描くようにしております。
34
+
35
+
36
+
14
-
37
+ そして必要に応じて
38
+
15
- トグルボタンでy軸のline/logスケールを切り替え可能な機能をつけております。
39
+ トグルボタンでy軸のline/logスケールを切り替え出来るようにしたいのです。
16
40
 
17
41
 
18
42
 
@@ -76,16 +100,16 @@
76
100
 
77
101
  matplotlib.use( 'WXAgg' )
78
102
 
103
+ import matplotlib.pyplot as plt
104
+
105
+ from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
106
+
107
+ from matplotlib.figure import Figure
108
+
79
109
 
80
110
 
81
111
  class MainFrame(wx.Frame):
82
112
 
83
- import matplotlib.pyplot as plt
84
-
85
- from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
86
-
87
- from matplotlib.figure import Figure
88
-
89
113
 
90
114
 
91
115
  def __init__(self):
@@ -120,21 +144,17 @@
120
144
 
121
145
  combobox_1 = wx.ComboBox(panel, wx.ID_ANY, 'select ScanList', choices = element_array, style = wx.CB_READONLY)
122
146
 
123
- print(combobox_1.GetSelection())
124
-
125
147
  combobox_1.Bind(wx.EVT_TEXT, self.Ontext)
126
148
 
127
-
149
+
128
150
 
129
151
  #button
130
152
 
131
153
  button_1 = wx.ToggleButton(panel, wx.ID_ANY, 'Log', size = ( 60, -1) )
132
154
 
133
- print(button_1.GetValue())
134
-
135
155
  button_1.Bind(wx.EVT_TOGGLEBUTTON, self.click_button_1)
136
156
 
137
-
157
+
138
158
 
139
159
  vbox_1 = wx.BoxSizer(wx.VERTICAL)
140
160
 
@@ -150,7 +170,7 @@
150
170
 
151
171
  vbox_1.Add((-1,10))
152
172
 
153
-
173
+
154
174
 
155
175
  vbox_1.Add(self.canvas, 1, wx.LEFT | wx.RIGHT |wx.EXPAND, 10)
156
176
 
@@ -158,22 +178,10 @@
158
178
 
159
179
  panel.SetSizer(vbox_1)
160
180
 
161
- #panel.subplot.set_title("Sample", fontsize = 12)
181
+
162
-
163
- #panel.subplot.set_xlabel("x")
164
-
165
- #panel.subplot.set_ylabel("y")
166
-
167
- #panel.subplot.xaxis.set_major_locator(ticker.MultipleLocator(100))
168
-
169
- #panel.subplot.yaxis.set_major_locator(ticker.MultipleLocator(100))
170
-
171
-
172
182
 
173
183
  def Ontext(self, event):
174
184
 
175
- #print(button_1.GetValue())
176
-
177
185
  self.plot.clear()
178
186
 
179
187
  combobox_1 = event.GetEventObject()
@@ -182,19 +190,15 @@
182
190
 
183
191
  drawdata = np.array(ScanData[combobox_1.GetSelection()])
184
192
 
185
- x = drawdata[:,1]
193
+ x = drawdata[:,0]
186
-
194
+
187
- y = drawdata[:,2]#[:,det]
195
+ y = drawdata[:,1]
188
-
189
- #if self.button_1.GetValuen == True:
190
-
191
- # self.plot.set_yscale('log')
192
196
 
193
197
  self.plot.plot(x, y, linestyle = "solid", marker = "o")
194
198
 
195
- axislabel = [row[1] for row in ScanDet]
199
+ axislabel = [row[0] for row in ScanDet]
196
-
200
+
197
- detlabel = [row[2] for row in ScanDet]
201
+ detlabel = [row[1] for row in ScanDet]
198
202
 
199
203
  self.plot.set_xlabel(axislabel[combobox_1.GetSelection()])
200
204
 
@@ -206,7 +210,7 @@
206
210
 
207
211
  self.canvas.draw()
208
212
 
209
-
213
+
210
214
 
211
215
  def click_button_1(self, event):
212
216
 
@@ -214,21 +218,21 @@
214
218
 
215
219
  drawdata = np.array(ScanData[self.combobox_1.GetSelection])
216
220
 
217
- x = drawdata[:,1]
221
+ x = drawdata[:,0]
218
-
222
+
219
- y = drawdata[:,2]#[:,det]
223
+ y = drawdata[:,1]
220
224
 
221
225
  plt.xscale("log")
222
226
 
223
227
  self.plot.plot(x, y, linestyle = "solid", marker = "o")
224
228
 
225
- axislabel = [row[1] for row in ScanDet]
229
+ axislabel = [row[0] for row in ScanDet]
226
-
230
+
227
- detlabel = [row[2] for row in ScanDet]
231
+ detlabel = [row[1] for row in ScanDet]
228
232
 
229
233
  self.plot.set_xlabel(axislabel[combobox_1.GetSelection()])
230
234
 
231
- self.plot.set_ylabel(detlabel[combobox_1.GetSelection()])
235
+ self.pldot.set_ylabel(detlabel[combobox_1.GetSelection()])
232
236
 
233
237
  self.plot.set_title(ScanList[combobox_1.GetSelection()][1])
234
238
 
@@ -238,19 +242,13 @@
238
242
 
239
243
 
240
244
 
241
- #self.subplot.legend()
242
-
243
-
244
-
245
-
246
-
247
245
  if __name__ == '__main__':
248
246
 
249
247
  ScanList = [["scan : 1","data 2018/07/05 13:00"],["scan : 2","data 2018/07/05 14:00"],["scan : 3","data 2018/07/05 15:00"]]
250
248
 
251
- ScanDet = [["#","xaxis_1","yaxis_1"],["#","xaxis_2","yaxis_2"],["#","xaxis_3","yaxis_3"]]
249
+ ScanDet = [["xaxis_1","yaxis_1"],["xaxis_2","yaxis_2"],["xaxis_3","yaxis_3"]]
252
-
250
+
253
- ScanData = [[[0,1,1],[1,2,2],[2,3,3],[3,4,4]],[[0,1,1],[1,2,4],[2,3,9],[3,4,16]],[[0,1,1],[1,2,0.5],[2,3,0.3],[3,4,0.25]]]
251
+ ScanData = [[[1,1],[2,2],[3,3],[4,4]],[[1,1],[2,4],[3,9],[4,16]],[[1,1],[2,0.5],[3,0.3],[4,0.25]]]
254
252
 
255
253
  app = wx.App()
256
254
 

2

コード挿入

2018/07/09 02:26

投稿

yamatail
yamatail

スコア77

test CHANGED
File without changes
test CHANGED
@@ -254,13 +254,11 @@
254
254
 
255
255
  app = wx.App()
256
256
 
257
- MainFrame().Show()```ここに言語を入力
257
+ MainFrame().Show()
258
-
259
- コード
258
+
260
-
259
+
260
+
261
- ```
261
+ ``````
262
-
263
- app.MainLoop()```
264
262
 
265
263
 
266
264
 

1

コードが挿入できてなかったので編集しました。

2018/07/05 06:14

投稿

yamatail
yamatail

スコア77

test CHANGED
File without changes
test CHANGED
@@ -254,7 +254,11 @@
254
254
 
255
255
  app = wx.App()
256
256
 
257
- MainFrame().Show()
257
+ MainFrame().Show()```ここに言語を入力
258
+
259
+ コード
260
+
261
+ ```
258
262
 
259
263
  app.MainLoop()```
260
264