如何使用sizer例程在不同的面板上找到支持多个标绘比例和Xaxis的代码?

2024-04-23 11:53:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在使用这个代码作为一个模型来修改一个应用程序,以支持在同一个轴上覆盖超过8个单独的绘图,并在两侧使用不同的比例。你知道吗

到目前为止我有几个问题。你知道吗

  1. 一些Y标签在左边,一些在右边。2或3在两侧(不是全部)重复(错误)。它似乎是在右侧,覆盖了一个重复造成胡言乱语。一个比例尺包含绘制的数据数量。

  2. 当应用程序停止时,黑色窗口(DOS提示窗口)不会消失。我有一个理论,创建了两个“canvas”块,一个是通过调用创建一个实例,使用一个调用创建一个canvas,另一个是创建一个绘图区域(不称之为canvas)。电话如下:

第1组

myLOG_Fig = m_plt.figure(figsize=(3.0, 3.0), dpi=100)
self.myLOG_PlotCanvas = FigCanvas( panel, -1, myLOG_Fig )

设置2

self.myLOG_HostAxes = host_subplot(111, axes_class=AA.Axes)

集合1需要将self.myLOG_PlotCanvas呈现给Sizer放置例程,该例程将图像(绘图区域画布)应用于面板(四个面板之一)。这套作品的伟大,直到我开始其他绘图(2至8)的画布。你知道吗

我找到了一个解决方案(第2组),它使用mpl工具包和AA来共享X轴,并呈现2个以上的比例。通过更改代码以允许设置2,我注意到了问题所在。绘图的比例和颜色正确。侧刻度看起来几乎不错(例外是在右边重复),我不能改变X轴标签和Y轴标签的字体大小。我可以用set 1控制颜色和字体大小。集合2对更改角色属性没有响应。还有一些代码必须使用集合2所需的代码(但我没有在这里列出)。我个人不认为这两个画布绘图区域是相同的,这也是为什么应用程序没有死掉的原因之一(黑色DOS窗口徘徊)。你知道吗

是否有更新版本的matplotlib和mpl\u工具包代码将例程连接到一个画布绘图区域?是否有一些代码可以满足我的要求(使用大小调整器等)来生成一个在每个选项卡上都有选项卡和绘图区域的应用程序?你知道吗


Tags: 代码self应用程序区域绘图画布fig标签
1条回答
网友
1楼 · 发布于 2024-04-23 11:53:07

Plot Generated from this code

以下是我对问题的解决方案(我在2013年发布)。在寻找答案和解决方案之后,我找到了几个代码片段,并将它们拼凑在一起,使它们成为一个“团队”。。。 省略一些设置代码以保持列出的代码简短。每个的数组 y轴是省略的部分之一。你知道吗

代码段如下:

类子帧(wx.框架): “”“子帧(2169行)” Sub-Frame类创建包含图形和画布的框架 用于打印图像。
包含以下方法:

        BtnPlot      - button to invoke select a file to plot
        BtnClear     - button to clear canvas image
        BtnClose     - button to close instance of SubFrame_L
        BtnWordDoc   - button to Export image to Word Document file
        BtnPrint     - button to Export image to Word Document file & Print
        BtnClipboard - button to Export image to Clipboard

        DoPlot_SLIK_File   - select a file to plot, then transfers to canvas
        myLOG_DrawPlot     - processes file to plot data arrays.
        RePaintL_Canvas    - re-draws canvas after a canvas "clear" 
        Display_SLIK_Parms - displays Parameters read from file
        BtnClose_EVT       - event handler to clean up and close instance
        DblClick_EVT       - 
"""

    intDPI    = 100
    #
    fltFigX = 12.0
    fltFigY =  4.28

    self.myLOG_Fig = plt.figure(num=None, figsize=( fltFigX, fltFigY ), dpi=intDPI)

    self.myLOG_Fig.subplots_adjust(right=0.85)

    # New version of axes_grid1 with axisartist is recommended
    # host_subplot returns ax which is formed using plt.
    #
    # uses matplotlib.pyplot as plt
    #                               111 = rows,cols,subplot #
    self.x_AA_Axes_L = host_subplot(111, axes_class=AA.Axes)
    #
    self.x_AA_Axes_L.axis["top"].set_visible( True )
    self.x_AA_Axes_L.set_axis_bgcolor( 'white' )    
    self.x_AA_Axes_L.set_autoscale_on( False   )      # <<< ONLY False works

    # *** ++++++++++++++++++++++++++++++++++ Set X-AXIS for all Y-Scales
    self.x_AA_Axes_L.set_xlabel("Time (min)",  fontsize=8, color='red')


    # _________________________Offsets___________________________________
    # Y Label Axis offset from X-Axis
    right_Offset1 = 0                          # Temperature
    right_Offset2  =  right_Offset1 + 50       # Accelerometer
    right_Offset3  =  right_Offset2 + 50       # 

    left_offset1   = 0                         # Motor/Batt Voltage
    left_offset2   = left_offset1 - 50         # Motor Amps
    left_offset3   = left_offset2 - 20         # TBD
    # _________________________Offsets___________________________________


    # *** INIT *** SLIKPAK ***
    # +++++++++++++++++++++++++++++ Battery Voltage  (green) [left @ 0)  #-50]
    self.x_AA_Axes_L.set_ylabel("Battery Voltage", fontsize=8, color='green')
    self.x_AA_Axes_L.set_ylim(ymin=0.0,ymax=40.0)

    # +++++++++++++++++++++++++++++ Motor Current     (red) [left @ 0]
    self.axes_1_L = self.x_AA_Axes_L.twinx()    # Use subplot Base axis

    self.newFixedAxis_1_L = self.axes_1_L.get_grid_helper().new_fixed_axis


    self.axes_1_L.axis["left"] = self.newFixedAxis_1_L(loc="left",
                                        axes=self.axes_1_L,
                                        offset=(left_offset2, 0))

    # axis is shared by Batt and Mot - left is displayed, right is off
    self.axes_1_L.axis["right"].set_visible( False )

    self.axes_1_L.set_ylabel("force (g)/Motor Current (amps)", fontsize=8, color='red')
    self.axes_1_L.set_ylim( ymin=0.0, ymax=10.0 )

    # +++++++++++++++++++++++++++++ Temperature  (blue)
    self.axes_2_L = self.x_AA_Axes_L.twinx()

    self.newFixedAxis_2_L = self.axes_2_L.get_grid_helper().new_fixed_axis

    self.axes_2_L.axis["right"] = self.newFixedAxis_2_L(loc="right",
                                        axes=self.axes_2_L,
                                        offset=(right_Offset1, 0))

    # right is displayed, left is off
    self.axes_2_L.set_ylabel("Temperature", fontsize=8, color='blue')
    self.axes_2_L.set_ylim(ymin=0.0,ymax=300.0) #, size=8) #,fontsize=8, color='green' )



    # +++++++++++++++++++++++++++++ Accelerometer
    self.axes_3_L = self.x_AA_Axes_L.twinx()    # Use subplot Base axis

    self.newFixedAxis_3 = self.axes_3_L.get_grid_helper().new_fixed_axis

    self.axes_3_L.axis["right"] = self.newFixedAxis_3(loc="right",
                                        axes=self.axes_3_L,
                                        offset=(right_Offset2, 0))

    self.axes_3_L.set_ylabel("force [X(g),Y(o),Z(m)]", fontsize=8, color='green')
    self.axes_3_L.set_ylim(ymin=0.0,ymax=10.0)


    self.myLOG_FigCanvas = FigCanvas( self, -1, self.myLOG_Fig )  

    # *** Add special action buttons - pan, zoom, etc
    #
    self.NavToolBar_L = NavigationToolbar( self.myLOG_FigCanvas )
    #
    self.NavToolBar_L.Realize()

    # Start Main Box (Verticle Box)
    self.vMainBoxSizer1 = wx.BoxSizer(wx.VERTICAL)
    # *** (v1) First, Add FigCanvas to Vertical Box
    self.vMainBoxSizer1.Add( self.myLOG_FigCanvas, proportion=1, border=5, \
                                    flag=wx.ALL | wx.EXPAND)

    # *** Start Horizontal Box
    self.hBoxSizer = wx.BoxSizer(wx.HORIZONTAL)
    # *** (h1) Add Navigation Tool along with buttons to hBoxSizer (horizontal Box)
    self.hBoxSizer.Add( self.NavToolBar_L, proportion=0, border=2, flag=wx.ALL)

    self.btnPlot  = wx.Button( self, wx.NewId(), "Plot"  )
    self.btnClear = wx.Button( self, wx.NewId(), "Clear" )
    self.btnClose = wx.Button( self, wx.NewId(), "Close" )

    self.btnWordDoc   = wx.Button( self, wx.NewId(), "WordDoc" )
    self.btnPrint     = wx.Button( self, wx.NewId(), "Print" )
    self.btnClipboard = wx.Button( self, wx.NewId(), "Clipboard" )

    # *** (h2) Now, Add buttons to hBoxSizer (horizontal Box)
    self.hBoxSizer.Add( self.btnPlot,      proportion=0, border=2, flag=wx.ALL)
    self.hBoxSizer.Add( self.btnClear,     proportion=0, border=2, flag=wx.ALL)
    self.hBoxSizer.Add( self.btnClose,     proportion=0, border=2, flag=wx.ALL)
    self.hBoxSizer.Add( self.btnWordDoc,   proportion=0, border=2, flag=wx.ALL)
    self.hBoxSizer.Add( self.btnPrint,     proportion=0, border=2, flag=wx.ALL)
    self.hBoxSizer.Add( self.btnClipboard, proportion=0, border=2, flag=wx.ALL)

    # *** (v2) Add self.hBoxSizer to Verticla Box
    self.vMainBoxSizer1.Add( self.hBoxSizer )
    # *** Finalize self.vMainBoxSizer1
    self.SetSizer( self.vMainBoxSizer1 )

    # **** BIND Buttons to Handlers
    # This Canvas supports double-click to open another canvas window
    self.myLOG_FigCanvas.Bind( wx.EVT_LEFT_DCLICK, self.DblClick_L_EVT )

    self.btnPlot.Bind(  wx.EVT_BUTTON, self.BtnPlot_L_EVT  )
    self.btnPlot.Enable( True )
    self.btnClear.Bind( wx.EVT_BUTTON, self.BtnClearPlot_L_EVT )
    self.btnClear.Enable( False )
    # *** connect to "Close Button"
    self.btnClose.Bind( wx.EVT_BUTTON, self.BtnClose_L_EVT )
    # *** Also connect to "EXIT Button" Strip
    self.Bind(wx.EVT_CLOSE, self.BtnClose_L_EVT)
    self.btnWordDoc.Bind(  wx.EVT_BUTTON, self.BtnWordDoc_L_EVT )
    self.btnWordDoc.Enable( False )
    self.btnPrint.Bind( wx.EVT_BUTTON, self.BtnPrint_L_EVT )
    self.btnPrint.Enable( False )
    self.btnClipboard.Bind( wx.EVT_BUTTON, self.BtnClipboard_L_EVT )
    self.btnClipboard.Enable( False )

    self.Layout()

代码结束。 绘图开始示例软件代码:

    try:
        # *** Battery Voltage (30 Volts) (green)
        # Number of Time entries must match number of VBatt entries
        self.x_AA_Axes_L.plot( self.fltArray_Time_L,
                                self.fltArray_VBatt_L, 
                linewidth=1, color=('green'))[0]       # [0] required !!!
    except:
        pass
    #
    try:
        # *** Phase               (1-4) [0-10](black)
        # Number of Time entries must match number of Phase entries
        self.axes_1_L.plot( self.fltArray_Time_L,
                            self.fltArray_Phase_L, linewidth=1,
                            color=('black'))[0]            # [0] required !!!
    except:
        pass
    #
    try:
        # *** BrushLess Motor Amps (3 Amps) [0-10](red)
        # Number of Time entries must match number of BrLsAmps entries
        self.axes_1_L.plot( self.fltArray_Time_L,
                            self.fltArray_BrLsAmps_L, linewidth=1,
                            color=('red'))[0]            # [0] required !!!
    except:
        pass
    #
    #
    try:
        # *** Temperature (72 degrees) (blue)
        # Number of Time entries must match number of Temp entries
        self.axes_2_L.plot( self.fltArray_Time_L,
                            self.fltArray_Temp_L, 
                linewidth=1, color=('blue'))[0]       # [0] required !!!
    except:
        pass
    #
    #
    #
    try:
        # *** Gx  Accelerometer    (g force)(0-10) (orange)      <<<<<<<<<<<<<<<< ORANGE
        #
        self.axes_3_L.plot( self.fltArray_Time_L,
                            self.fltArray_AccX_L, linewidth=1,
                            color=('orange'))[0]          # [0] required !!!
    except:
        pass
    #
    try:
        # *** Gy  Accelerometer    (g force)(0-10) (green)
        #
        self.axes_3_L.plot( self.fltArray_Time_L,
                            self.fltArray_AccY_L, linewidth=1,
                            color=('green'))[0]          # [0] required !!!
    except:
        pass
    #
    #
    try:
        # *** Gz  Accelerometer    (g force)(0-10) (magenta)
        #
        self.axes_3_L.plot( self.fltArray_Time_L,
                            self.fltArray_AccZ_L, linewidth=1,
                            color=('magenta'))[0]          # [0] required !!!
    except:
        pass

代码结束

canvas窗口的有趣特性是它支持双击,这会导致出现一个新的(空白)窗口。为了节省空间,省略了一些代码。你知道吗

选择一个包含4到7列数据的文件。每一列都呈现给一个数组[](每个数组都有不同的名称)。将保留插入数组的项目的确切数目的计数。一个数组\u count[]将匹配数据数组中的每个条目。并将指示每个x轴步长的时间步长(本例中为0.0167)。图显示的一个例子已经上传给那些感兴趣的人。你知道吗

相关问题 更多 >