gpt4 book ai didi

python - wxpython 将多个 wx.NumCtrl 放入数据结构中以便在 matplotlib 中绘图

转载 作者:太空宇宙 更新时间:2023-11-03 18:53:00 29 4
gpt4 key购买 nike

我正在 wxpython 中编写我的第一个 gui,并且我相当困惑如何正确地将输入的数据从 NumCtrl 转换为可以由 matplotlib 轻松操作以给出我想要的图的数据结构。我的 GUI 模板如下所示

GUI template

基本上,对于每个角度,我想输入有 (C) 和没有 (U) 准直器到位的计数。当我按下绘图按钮时,我会计算每个 wx.NumCtrl 中的数字并绘制图表。目前,我们将计数输入电子表格并使用 R 中的 ggplot2 进行绘图。不过,我想用一个更用户友好的 GUI 来替换它,该 GUI 是在同一脚本中完成绘图而编写的。下面给出了所需的最终图的示例

enter image description here

以下是相关代码片段:

#Set input boxes for results
numctrl_ccm90 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ucm90 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ccp90 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ucp90 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ccm75 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ucm75 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ccp75 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ucp75 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ccm60 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ucm60 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ccp60 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ucp60 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ccm45 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ucm45 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ccp45 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ucp45 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ccm30 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ucm30 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ccp30 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ucp30 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ccm15 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ucm15 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ccp15 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_ucp15 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_cc0 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_uc0 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
numctrl_fwhm = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)

fgs.AddMany([(angle),(count_c), (count_u),(angle2),(count_c2), (count_u2),
(wx.StaticText(panel, -1, '-90')),
(numctrl_ccm90,0,wx.EXPAND,5),
(numctrl_ucm90,0,wx.EXPAND,5),
(wx.StaticText(panel, -1, '90')),
(numctrl_ccp90,0,wx.EXPAND,5),
(numctrl_ucp90,0,wx.EXPAND,5),
(wx.StaticText(panel, -1, '-75')),
(numctrl_ccm75,0,wx.EXPAND,5),
(numctrl_ucm75,0,wx.EXPAND,5),
(wx.StaticText(panel, -1, '75')),
(numctrl_ccp75,0,wx.EXPAND,5),
(numctrl_ucp75,0,wx.EXPAND,5),
(wx.StaticText(panel, -1, '-60')),
(numctrl_ccm60,0,wx.EXPAND,5),
(numctrl_ucm60,0,wx.EXPAND,5),
(wx.StaticText(panel, -1, '60')),
(numctrl_ccp60,0,wx.EXPAND,5),
(numctrl_ucp60,0,wx.EXPAND,5),
(wx.StaticText(panel, -1, '-45')),
(numctrl_ccm45,0,wx.EXPAND,5),
(numctrl_ucm45,0,wx.EXPAND,5),
(wx.StaticText(panel, -1, '45')),
(numctrl_ccp45,0,wx.EXPAND,5),
(numctrl_ucp45,0,wx.EXPAND,5),
(wx.StaticText(panel, -1, '-30')),
(numctrl_ccm30,0,wx.EXPAND,5),
(numctrl_ucm30,0,wx.EXPAND,5),
(wx.StaticText(panel, -1, '30')),
(numctrl_ccp30,0,wx.EXPAND,5),
(numctrl_ucp30,0,wx.EXPAND,5),
(wx.StaticText(panel, -1, '-15')),
(numctrl_ccm15,0,wx.EXPAND,5),
(numctrl_ucm15,0,wx.EXPAND,5),
(wx.StaticText(panel, -1, '15')),
(numctrl_ccp15,0,wx.EXPAND,5),
(numctrl_ucp15,0,wx.EXPAND,5),
(wx.StaticText(panel, -1, '0')),
(numctrl_cc0,0,wx.EXPAND,5),
(numctrl_uc0,0,wx.EXPAND,5),
(wx.StaticText(panel, -1, '')),
(wx.StaticText(panel, -1, '')),
(wx.StaticText(panel, -1, '')),
(wx.StaticText(panel, -1, '')),
(wx.StaticText(panel, -1, '')),
(wx.StaticText(panel, -1, '')),
(wx.StaticText(panel, -1, 'FWHM')),
(numctrl_fwhm,0,wx.EXPAND,5),
(wx.StaticText(panel, -1, 'deg'))])

其中numctrl_ccm90numctrl_ucp90是与-90deg的准直计数和+90deg的非准直计数相对应的小部件。

我认为我应该创建某种绑定(bind),用每个 NumCtrl 小部件的计数更新变量/列表/字典。我不确定应该如何执行此操作以及哪种格式最适合后续绘图。例如,当我在 numctrl_ccm90 中输入 1234 计数时,我想将此信息存储为 counts: 1234 collimator:Y Angle: -90。

当我完成数据输入后,我将按下绘图按钮,该按钮将拾取每个 numCtrl 框中的计数值(除了 fwhm numctrl),并将所有这些信息放置在允许绘图的结构中

对于绘图 - 我绘制了准直和非准直探测器的归一化计数与角度的关系。完成这项任务的最佳方法是什么?这一刻我很失落

<小时/>

现在我的计数已在列表列表中

self.angle_list = []
self.angles_list.append([-90,'U',self.numctrl_ucm90.GetValue()])
self.angles_list.append([-75,'U',self.numctrl_ucm75.GetValue()])

其中angle_list的每个元素都是一个格式为[角度、准直器、计数]的列表

不知道这对我的绘图有什么帮助。我需要的是“U”与“C”两种组合的角度与计数的散点图。

最佳答案

我建议自动生成 3 个控件列表,然后您可以按顺序运行这些列表,填充网格大小调整器后,在每个绘图上单击再次运行每个控件,选取要放入两个列表中的值提供给绘图的元组或数组。例如

self.Angles = range(-90, 100, 15)
self.Texts = [wx.StaticText(panel, -1, '%d' % a) for a in Angles]
self.CCount = [NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB) for a in Angles]
self.UCount = [NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB) for a in Angles]

添加到 sizer 和 OnPlot 方法中:

   Cs = [ctrl.GetValue() for ctrl in self.CCount]
Us = [ctrl.GetValue() for ctrl in self.UCount]
plot(zip(Cs, Angles)) # or something similar

等等...

关于python - wxpython 将多个 wx.NumCtrl 放入数据结构中以便在 matplotlib 中绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17879301/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com