質問編集履歴
7
必要な部分だけにした
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
wxpython
|
1
|
+
【wxpython】コンボボックスとトグルボタンの値をテキストボックスに表示させたい。
|
body
CHANGED
@@ -1,146 +1,69 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
|
3
|
-
|
3
|
+
wxpythonでGUiを作成中です。
|
4
|
-
リストは3つ作っています。
|
5
|
-
ScanList = [["番号","データタイトル"],...]
|
6
|
-
ScanDet = [["x軸","y軸"],...]
|
7
|
-
ScanData = グラフに用いるデータ[x軸,y軸,スキャン番号]の三次元配列
|
8
4
|
|
9
|
-
|
5
|
+
GUIにはコンボボックスとトグルボタンとStaticTextを配置しました。
|
10
6
|
|
11
|
-
|
7
|
+
コンボボックスでOntextイベントを行う際
|
12
|
-
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"]]
|
13
|
-
ScanDet = [["xaxis_1","yaxis_1"],["xaxis_2","yaxis_2"],["xaxis_3","yaxis_3"]]
|
14
|
-
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]]]
|
15
|
-
```
|
16
|
-
|
8
|
+
コンボボックス内のテキストと同時にトグルボタンのステータス(TRUE or FALSE)も取得させたいです。
|
17
9
|
|
18
|
-
コンボボックスのGetSelection()でステータスをとり、3つのデータのindexで紐つけし、必要なデータをそれぞれ抽出しグラフを描くようにしております。
|
19
|
-
|
10
|
+
以下、コードになります。
|
20
|
-
トグルボタンでy軸のline/logスケールを切り替え出来るようにしたいのです。
|
21
|
-

|
22
|
-
イメージは、
|
23
11
|
|
24
|
-
コンボボックスでホイールをころころする
|
25
|
-
選択されたデータのグラフが表示される ⇒ これは実現済み
|
26
|
-
|
27
|
-
次にトグルボタンでlogを選択する
|
28
|
-
コンボボックスでホイールをころころする
|
29
|
-
選択されたデータのグラフがLogで表示される ⇒ ここで引っかかっています
|
30
|
-
|
31
|
-
|
32
|
-
まだまだpythonの階層構造自体知識が不十分なため難儀しております。
|
33
|
-
|
34
|
-
コードの書き方等で「そもそも・・・」というお話もあるかと思いますので、
|
35
|
-
何でもよいので、ご教授頂けると大変助かります。
|
36
|
-
|
37
|
-
### 発生している問題・エラーメッセージ
|
38
|
-
|
39
|
-
コンボボックスで2次元グラフを表示させるところまではいきました。
|
40
|
-
が、line/log切り替え機能がうまく合わさりません。
|
41
|
-
|
42
|
-
logに切り替えると
|
43
|
-
AttributeError:'MainFrame' object has no attribute 'combobox_1'
|
44
|
-
とエラーをはきます。
|
45
|
-
|
46
|
-
Ontext()メソッドのなかで
|
47
|
-
ToggleButton.GetValue()が取れれば下の様なコードを挟めて良いのかなと思ったりするのですが、うまくいきません。
|
48
|
-
|
49
|
-
if self.button_1.GetValuen == True:
|
50
|
-
self.plot.set_yscale('log')
|
51
|
-
|
52
|
-
|
53
|
-
### 該当のソースコード
|
54
|
-
|
55
12
|
```python
|
56
13
|
import wx
|
57
|
-
import
|
14
|
+
import os
|
58
15
|
|
59
|
-
import matplotlib
|
60
|
-
matplotlib.interactive( True )
|
61
|
-
matplotlib.use( 'WXAgg' )
|
62
|
-
import matplotlib.pyplot as plt
|
63
|
-
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
|
64
|
-
from matplotlib.figure import Figure
|
65
|
-
|
66
16
|
class MainFrame(wx.Frame):
|
67
17
|
|
68
18
|
def __init__(self):
|
69
|
-
wx.Frame.__init__(self, None, wx.ID_ANY, 'logplot'
|
19
|
+
wx.Frame.__init__(self, None, wx.ID_ANY, 'logplot')
|
70
20
|
panel = wx.Panel(self, wx.ID_ANY)
|
71
21
|
panel.SetBackgroundColour(wx.Colour(128, 128, 128))
|
72
|
-
plt.style.use('bmh')
|
73
|
-
#matplotlib figure
|
74
|
-
figure = matplotlib.figure.Figure()
|
75
|
-
figure.subplots_adjust(left=0.075, bottom=0.1, right=0.95, top=0.95, wspace=0.15, hspace=0.15)
|
76
|
-
self.plot = figure.add_subplot( 111 ,xlabel = 'X', ylabel = 'y')
|
77
|
-
#canvas
|
78
|
-
self.canvas = FigureCanvasWxAgg(panel, wx.ID_ANY, figure)
|
79
|
-
self.canvas.SetBackgroundColour( wx.Colour( 100, 255, 255 ))
|
80
22
|
|
81
23
|
#combobox
|
82
|
-
element_array = [row[0] for row in ScanList]
|
83
|
-
combobox_1 = wx.ComboBox(panel, wx.ID_ANY, 'select ScanList', choices =
|
24
|
+
combobox_1 = wx.ComboBox(panel, wx.ID_ANY, 'select ScanList', choices = ("1","2","3"), style = wx.CB_READONLY)
|
84
25
|
combobox_1.Bind(wx.EVT_TEXT, self.Ontext)
|
85
26
|
|
86
27
|
#button
|
87
|
-
button_1 = wx.ToggleButton(panel, wx.ID_ANY, 'Log'
|
28
|
+
button_1 = wx.ToggleButton(panel, wx.ID_ANY, 'Line/Log')
|
88
|
-
button_1.Bind(wx.EVT_TOGGLEBUTTON, self.
|
29
|
+
button_1.Bind(wx.EVT_TOGGLEBUTTON, self.button_click)
|
30
|
+
|
89
|
-
|
31
|
+
#Text
|
32
|
+
text_1 = wx.StaticText(panel, wx.ID_ANY, )
|
33
|
+
|
90
34
|
vbox_1 = wx.BoxSizer(wx.VERTICAL)
|
91
|
-
hbox_1 = wx.BoxSizer(wx.HORIZONTAL)
|
92
|
-
|
35
|
+
vbox_1.Add(combobox_1, 0, wx.LEFT | wx.RIGHT, 10)
|
93
|
-
|
36
|
+
vbox_1.Add(button_1, 0, wx.RIGHT, 10)
|
94
|
-
vbox_1.Add(hbox_1)
|
95
|
-
|
96
|
-
vbox_1.Add((-1,10))
|
97
|
-
|
98
|
-
vbox_1.Add(
|
37
|
+
vbox_1.Add(text_1, 0, wx.RIGHT, 10)
|
99
|
-
|
38
|
+
|
100
39
|
panel.SetSizer(vbox_1)
|
101
40
|
|
41
|
+
def button_click(self, event):
|
42
|
+
button_1 = event.GetEventObject()
|
43
|
+
if button_1.GetValue():
|
44
|
+
button_1.SetLabel("Log")
|
45
|
+
else:
|
46
|
+
button_1.SetLabel("Line")
|
47
|
+
print(button_1.GetValue())
|
48
|
+
|
102
49
|
def Ontext(self, event):
|
103
|
-
|
50
|
+
#print(button_1.GetValue())
|
104
51
|
combobox_1 = event.GetEventObject()
|
105
|
-
button_1 = event.GetEventObject()
|
106
|
-
drawdata = np.array(ScanData[combobox_1.GetSelection()])
|
107
|
-
x = drawdata[:,0]
|
108
|
-
y = drawdata[:,1]
|
109
|
-
self.plot.plot(x, y, linestyle = "solid", marker = "o")
|
110
|
-
axislabel = [row[0] for row in ScanDet]
|
111
|
-
detlabel = [row[1] for row in ScanDet]
|
112
|
-
self.plot.set_xlabel(axislabel[combobox_1.GetSelection()])
|
113
|
-
self.plot.set_ylabel(detlabel[combobox_1.GetSelection()])
|
114
|
-
self.plot.set_title(ScanList[combobox_1.GetSelection()][1])
|
115
|
-
self.plot.grid(which = "major", color = "black", linestyle = "dashed")
|
116
|
-
self.canvas.draw()
|
117
|
-
|
118
|
-
|
52
|
+
print(combobox_1.GetValue())
|
119
|
-
|
53
|
+
|
120
|
-
drawdata = np.array(ScanData[self.combobox_1.GetSelection])
|
121
|
-
x = drawdata[:,0]
|
122
|
-
y = drawdata[:,1]
|
123
|
-
plt.xscale("log")
|
124
|
-
self.plot.plot(x, y, linestyle = "solid", marker = "o")
|
125
|
-
axislabel = [row[0] for row in ScanDet]
|
126
|
-
detlabel = [row[1] for row in ScanDet]
|
127
|
-
self.plot.set_xlabel(axislabel[combobox_1.GetSelection()])
|
128
|
-
self.pldot.set_ylabel(detlabel[combobox_1.GetSelection()])
|
129
|
-
self.plot.set_title(ScanList[combobox_1.GetSelection()][1])
|
130
|
-
self.plot.grid(which = "major", color = "black", linestyle = "dashed")
|
131
|
-
self.canvas.draw()
|
132
|
-
|
133
54
|
if __name__ == '__main__':
|
134
|
-
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"]]
|
135
|
-
ScanDet = [["xaxis_1","yaxis_1"],["xaxis_2","yaxis_2"],["xaxis_3","yaxis_3"]]
|
136
|
-
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]]]
|
137
55
|
app = wx.App()
|
138
56
|
MainFrame().Show()
|
57
|
+
app.MainLoop()
|
139
58
|
|
140
|
-
``````
|
141
59
|
|
60
|
+
```
|
142
|
-
###
|
61
|
+
###分からないこと
|
62
|
+
・statictextにコンボボックスの値とトグルボタンの値を受け渡す方法
|
63
|
+
イメージは、Ontext()イベントでコンボボックスをマウスのホイールでころころするとその都度コンボボックスのテキスト値とトグルボタンの値を読み取って表示させることです。
|
143
64
|
|
65
|
+
|
66
|
+
|
144
67
|
### 補足情報(FW/ツールのバージョンなど)
|
145
68
|
windows 7 professional 64bit
|
146
69
|
python3.6
|
6
表題を変更
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
2次元グラフをボタンとコンボボックスで切り替えて表示させたい。
|
1
|
+
wxpythonでmatplotlibを用いた2次元グラフをボタンとコンボボックスで切り替えて表示させたい。
|
body
CHANGED
File without changes
|
5
タグを追加
title
CHANGED
File without changes
|
body
CHANGED
File without changes
|
4
画像の添付
title
CHANGED
File without changes
|
body
CHANGED
@@ -14,11 +14,21 @@
|
|
14
14
|
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]]]
|
15
15
|
```
|
16
16
|
製作中のGUIは、データ番号をコンボボックスで選びながら2次元グラフを表示させるものです。
|
17
|
+
|
17
18
|
コンボボックスのGetSelection()でステータスをとり、3つのデータのindexで紐つけし、必要なデータをそれぞれ抽出しグラフを描くようにしております。
|
18
|
-
|
19
19
|
そして必要に応じて
|
20
20
|
トグルボタンでy軸のline/logスケールを切り替え出来るようにしたいのです。
|
21
|
+

|
22
|
+
イメージは、
|
21
23
|
|
24
|
+
コンボボックスでホイールをころころする
|
25
|
+
選択されたデータのグラフが表示される ⇒ これは実現済み
|
26
|
+
|
27
|
+
次にトグルボタンでlogを選択する
|
28
|
+
コンボボックスでホイールをころころする
|
29
|
+
選択されたデータのグラフがLogで表示される ⇒ ここで引っかかっています
|
30
|
+
|
31
|
+
|
22
32
|
まだまだpythonの階層構造自体知識が不十分なため難儀しております。
|
23
33
|
|
24
34
|
コードの書き方等で「そもそも・・・」というお話もあるかと思いますので、
|
3
コードの変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,12 +1,24 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
|
3
3
|
3次元データ[データ番号,x軸,y軸]を扱うGUIを製作中です。
|
4
|
+
リストは3つ作っています。
|
4
|
-
|
5
|
+
ScanList = [["番号","データタイトル"],...]
|
6
|
+
ScanDet = [["x軸","y軸"],...]
|
7
|
+
ScanData = グラフに用いるデータ[x軸,y軸,スキャン番号]の三次元配列
|
5
8
|
|
6
|
-
|
9
|
+
以下、コード
|
7
|
-
コンボボックスのgetselection()を用いてデータ番号と2次元データを紐つけしてグラフを描くようにしております。
|
8
|
-
トグルボタンでy軸のline/logスケールを切り替え可能な機能をつけております。
|
9
10
|
|
11
|
+
```python
|
12
|
+
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"]]
|
13
|
+
ScanDet = [["xaxis_1","yaxis_1"],["xaxis_2","yaxis_2"],["xaxis_3","yaxis_3"]]
|
14
|
+
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]]]
|
15
|
+
```
|
16
|
+
製作中のGUIは、データ番号をコンボボックスで選びながら2次元グラフを表示させるものです。
|
17
|
+
コンボボックスのGetSelection()でステータスをとり、3つのデータのindexで紐つけし、必要なデータをそれぞれ抽出しグラフを描くようにしております。
|
18
|
+
|
19
|
+
そして必要に応じて
|
20
|
+
トグルボタンでy軸のline/logスケールを切り替え出来るようにしたいのです。
|
21
|
+
|
10
22
|
まだまだpythonの階層構造自体知識が不十分なため難儀しております。
|
11
23
|
|
12
24
|
コードの書き方等で「そもそも・・・」というお話もあるかと思いますので、
|
@@ -37,11 +49,11 @@
|
|
37
49
|
import matplotlib
|
38
50
|
matplotlib.interactive( True )
|
39
51
|
matplotlib.use( 'WXAgg' )
|
52
|
+
import matplotlib.pyplot as plt
|
53
|
+
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
|
54
|
+
from matplotlib.figure import Figure
|
40
55
|
|
41
56
|
class MainFrame(wx.Frame):
|
42
|
-
import matplotlib.pyplot as plt
|
43
|
-
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
|
44
|
-
from matplotlib.figure import Figure
|
45
57
|
|
46
58
|
def __init__(self):
|
47
59
|
wx.Frame.__init__(self, None, wx.ID_ANY, 'logplot', size = (1000, 800))
|
@@ -59,14 +71,12 @@
|
|
59
71
|
#combobox
|
60
72
|
element_array = [row[0] for row in ScanList]
|
61
73
|
combobox_1 = wx.ComboBox(panel, wx.ID_ANY, 'select ScanList', choices = element_array, style = wx.CB_READONLY)
|
62
|
-
print(combobox_1.GetSelection())
|
63
74
|
combobox_1.Bind(wx.EVT_TEXT, self.Ontext)
|
64
|
-
|
75
|
+
|
65
76
|
#button
|
66
77
|
button_1 = wx.ToggleButton(panel, wx.ID_ANY, 'Log', size = ( 60, -1) )
|
67
|
-
print(button_1.GetValue())
|
68
78
|
button_1.Bind(wx.EVT_TOGGLEBUTTON, self.click_button_1)
|
69
|
-
|
79
|
+
|
70
80
|
vbox_1 = wx.BoxSizer(wx.VERTICAL)
|
71
81
|
hbox_1 = wx.BoxSizer(wx.HORIZONTAL)
|
72
82
|
hbox_1.Add(combobox_1, wx.ALIGN_CENTER)
|
@@ -74,57 +84,46 @@
|
|
74
84
|
vbox_1.Add(hbox_1)
|
75
85
|
|
76
86
|
vbox_1.Add((-1,10))
|
77
|
-
|
87
|
+
|
78
88
|
vbox_1.Add(self.canvas, 1, wx.LEFT | wx.RIGHT |wx.EXPAND, 10)
|
79
89
|
|
80
90
|
panel.SetSizer(vbox_1)
|
81
|
-
|
91
|
+
|
82
|
-
#panel.subplot.set_xlabel("x")
|
83
|
-
#panel.subplot.set_ylabel("y")
|
84
|
-
#panel.subplot.xaxis.set_major_locator(ticker.MultipleLocator(100))
|
85
|
-
#panel.subplot.yaxis.set_major_locator(ticker.MultipleLocator(100))
|
86
|
-
|
87
92
|
def Ontext(self, event):
|
88
|
-
#print(button_1.GetValue())
|
89
93
|
self.plot.clear()
|
90
94
|
combobox_1 = event.GetEventObject()
|
91
95
|
button_1 = event.GetEventObject()
|
92
96
|
drawdata = np.array(ScanData[combobox_1.GetSelection()])
|
93
|
-
x = drawdata[:,
|
97
|
+
x = drawdata[:,0]
|
94
|
-
y = drawdata[:,
|
98
|
+
y = drawdata[:,1]
|
95
|
-
#if self.button_1.GetValuen == True:
|
96
|
-
# self.plot.set_yscale('log')
|
97
99
|
self.plot.plot(x, y, linestyle = "solid", marker = "o")
|
98
|
-
axislabel = [row[
|
100
|
+
axislabel = [row[0] for row in ScanDet]
|
99
|
-
detlabel = [row[
|
101
|
+
detlabel = [row[1] for row in ScanDet]
|
100
102
|
self.plot.set_xlabel(axislabel[combobox_1.GetSelection()])
|
101
103
|
self.plot.set_ylabel(detlabel[combobox_1.GetSelection()])
|
102
104
|
self.plot.set_title(ScanList[combobox_1.GetSelection()][1])
|
103
105
|
self.plot.grid(which = "major", color = "black", linestyle = "dashed")
|
104
106
|
self.canvas.draw()
|
105
|
-
|
107
|
+
|
106
108
|
def click_button_1(self, event):
|
107
109
|
self.plot.clear()
|
108
110
|
drawdata = np.array(ScanData[self.combobox_1.GetSelection])
|
109
|
-
x = drawdata[:,
|
111
|
+
x = drawdata[:,0]
|
110
|
-
y = drawdata[:,
|
112
|
+
y = drawdata[:,1]
|
111
113
|
plt.xscale("log")
|
112
114
|
self.plot.plot(x, y, linestyle = "solid", marker = "o")
|
113
|
-
axislabel = [row[
|
115
|
+
axislabel = [row[0] for row in ScanDet]
|
114
|
-
detlabel = [row[
|
116
|
+
detlabel = [row[1] for row in ScanDet]
|
115
117
|
self.plot.set_xlabel(axislabel[combobox_1.GetSelection()])
|
116
|
-
self.
|
118
|
+
self.pldot.set_ylabel(detlabel[combobox_1.GetSelection()])
|
117
119
|
self.plot.set_title(ScanList[combobox_1.GetSelection()][1])
|
118
120
|
self.plot.grid(which = "major", color = "black", linestyle = "dashed")
|
119
121
|
self.canvas.draw()
|
120
122
|
|
121
|
-
#self.subplot.legend()
|
122
|
-
|
123
|
-
|
124
123
|
if __name__ == '__main__':
|
125
124
|
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"]]
|
126
|
-
ScanDet = [["
|
125
|
+
ScanDet = [["xaxis_1","yaxis_1"],["xaxis_2","yaxis_2"],["xaxis_3","yaxis_3"]]
|
127
|
-
ScanData = [[[
|
126
|
+
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]]]
|
128
127
|
app = wx.App()
|
129
128
|
MainFrame().Show()
|
130
129
|
|
2
コード挿入
title
CHANGED
File without changes
|
body
CHANGED
@@ -126,11 +126,10 @@
|
|
126
126
|
ScanDet = [["#","xaxis_1","yaxis_1"],["#","xaxis_2","yaxis_2"],["#","xaxis_3","yaxis_3"]]
|
127
127
|
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]]]
|
128
128
|
app = wx.App()
|
129
|
-
MainFrame().Show()
|
129
|
+
MainFrame().Show()
|
130
|
-
コード
|
131
|
-
```
|
132
|
-
app.MainLoop()```
|
133
130
|
|
131
|
+
``````
|
132
|
+
|
134
133
|
### 試したこと
|
135
134
|
|
136
135
|
### 補足情報(FW/ツールのバージョンなど)
|
1
コードが挿入できてなかったので編集しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -126,7 +126,9 @@
|
|
126
126
|
ScanDet = [["#","xaxis_1","yaxis_1"],["#","xaxis_2","yaxis_2"],["#","xaxis_3","yaxis_3"]]
|
127
127
|
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]]]
|
128
128
|
app = wx.App()
|
129
|
-
MainFrame().Show()
|
129
|
+
MainFrame().Show()```ここに言語を入力
|
130
|
+
コード
|
131
|
+
```
|
130
132
|
app.MainLoop()```
|
131
133
|
|
132
134
|
### 試したこと
|