设置限制Matplotlib或PyQtGraph的单个Y标签?

时间:2019-02-27 05:14:22

标签: python matplotlib

如何使用matplotlib或pyqtgraph在左侧的单个/单个Y标签中添加所有极限值。我已经管理了示例图表,并附在此处。

import wx
import matplotlib
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.figure import Figure
import numpy as np


class TopPanel(wx.Panel):
    def __init__(self,parent):
        wx.Panel.__init__(self, parent = parent)

        self.figure = Figure()

        #wx.Button(self,wx.ID_ANY, label="Button 1")
        self.SetBackgroundColour("red")
        self.axes = self.figure.add_subplot(111)
        self.canvas = FigureCanvas(self,-1,self.figure)
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.canvas, 1, wx.EXPAND)
        self.SetSizer(self.sizer)
        self.axes.set_xlabel("Time")
        self.axes.set_ylabel("A/D Counts")

    def draw(self):
        x = np.arange(0,5,0.01)
        y = np.sin(np.pi*x)
        self.axes.plot(x,y)

    def changeAxes(self, min, max):
        self.axes.set_ylim(float(min),float(max))
        self.canvas.draw()

class BottomPanel(wx.Panel):
    def __init__(self,parent, top):
        wx.Panel.__init__(self, parent = parent)
        #wx.Button(self,wx.ID_ANY, label="Button 2")
        #self.SetBackgroundColour('Blue')

        self.graph = top

        self.togglebuttonStart = wx.ToggleButton(self,wx.ID_ANY,label="Start", pos=(10,10))
        self.togglebuttonStart.Bind(wx.EVT_TOGGLEBUTTON, self.OnStartClick)

        labelChannels = wx.StaticText(self, wx.ID_ANY, "Analog Inputs", pos=(200, 10))
        self.cbl0 = wx.CheckBox(self,wx.ID_ANY, "A0", pos=(200, 30))
        self.cbl1 = wx.CheckBox(self, wx.ID_ANY, "A1", pos=(200, 45))
        self.cbl2 = wx.CheckBox(self, wx.ID_ANY, "A2", pos=(200, 60))

        self.Bind(wx.EVT_CHECKBOX, self.OnChecked)

        self.textboxSampleTime = wx.TextCtrl(self,wx.ID_ANY, "1000", pos=(200,115), size=(50,-1))
        self.ButtonSend = wx.Button(self,wx.ID_ANY, "Send", pos=(255,115), size=(50,-1))
        self.ButtonSend.Bind(wx.EVT_BUTTON, self.OnSend)

        # A0 limit Values
        labelMinY0 = wx.StaticText(self,wx.ID_ANY,"A0 Min Y", pos=(400,10))
        self.textboxMinYAxis0 = wx.TextCtrl(self,wx.ID_ANY, "0", pos=(400,30))
        labelMaxY0 = wx.StaticText(self, wx.ID_ANY, "A0 Max Y", pos=(400, 55))
        self.textboxMaxYAxis0 = wx.TextCtrl(self, wx.ID_ANY, "1024", pos=(400, 75))
        self.buttonRange0 = wx.Button(self, wx.ID_ANY, "Set Y0 Axis", pos=(400, 115))
        self.buttonRange0.Bind(wx.EVT_BUTTON, self.SetButtonRange0)

        # A1 limit Values
        labelMinY1 = wx.StaticText(self, wx.ID_ANY, "A1 Min Y", pos=(530, 10))
        self.textboxMinYAxis1 = wx.TextCtrl(self, wx.ID_ANY, "0", pos=(530, 30))
        labelMaxY1 = wx.StaticText(self, wx.ID_ANY, "A1 Max Y", pos=(530, 55))
        self.textboxMaxYAxis1 = wx.TextCtrl(self, wx.ID_ANY, "1024", pos=(530, 75))
        self.buttonRange1 = wx.Button(self, wx.ID_ANY, "Set Y1 Axis", pos=(530, 115))
        self.buttonRange1.Bind(wx.EVT_BUTTON, self.SetButtonRange1)

        # A2 limit Values
        labelMinY2 = wx.StaticText(self, wx.ID_ANY, "A2 Min Y", pos=(650, 10))
        self.textboxMinYAxis2 = wx.TextCtrl(self, wx.ID_ANY, "0", pos=(650, 30))
        labelMaxY2 = wx.StaticText(self, wx.ID_ANY, "A2 Max Y", pos=(650, 55))
        self.textboxMaxYAxis2 = wx.TextCtrl(self, wx.ID_ANY, "1024", pos=(650, 75))
        self.buttonRange2 = wx.Button(self, wx.ID_ANY, "Set Y2 Axis", pos=(650, 115))
        self.buttonRange2.Bind(wx.EVT_BUTTON, self.SetButtonRange2)

    def SetButtonRange0(self, event):
        #print("Axis Button Clicked")
        min = self.textboxMinYAxis0.GetValue()
        max = self.textboxMaxYAxis0.GetValue()
        print("(%s, %s)"% (min, max))

        self.graph.changeAxes(min,max);  # How to add it to Single Y-axis label?

    def SetButtonRange1(self, event):
        # print("Axis Button Clicked")
        min = self.textboxMinYAxis1.GetValue()
        max = self.textboxMaxYAxis1.GetValue()
        print("(%s, %s)" % (min, max))

        self.graph.changeAxes(min, max); # How to add it to Single Y-axis label?

    def SetButtonRange2(self, event):
        # print("Axis Button Clicked")
        min = self.textboxMinYAxis2.GetValue()
        max = self.textboxMaxYAxis2.GetValue()
        print("(%s, %s)" % (min, max))

如何将其添加到单个Y轴标签?

        self.graph.changeAxes(min, max); 


    def OnSend(self,event):
        val = self.textboxSampleTime.GetValue()
        print(val)

    def OnChecked(self,event):
        cb = event.GetEventObject()
        print("%s is clicked" %(cb.GetLabel()))

    def OnStartClick(self,event):
        val = self.togglebuttonStart.GetValue()
        if(val == True):
            self.togglebuttonStart.SetLabel("Stop")
            self.togglebuttonStart.SetBackgroundColour("red")
        else:
            self.togglebuttonStart.SetLabel("Start")
            self.togglebuttonStart.SetBackgroundColour("green")

class Main(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, parent=None, title="App v0", size=(600,600))
        splitter = wx.SplitterWindow(self)
        top = TopPanel(splitter)
        #bottom = BottomPanel(splitter)
        bottom = BottomPanel(splitter,top)
        splitter.SplitHorizontally(top, bottom)
        splitter.SetMinimumPaneSize(300)
        top.draw()

if __name__ == '__main__':
    app = wx.App()
    frame = Main()
    frame.Show()
    app.MainLoop()

代码是使用WxPython和matplotlib完成的。顶部面板用于绘制折线图,​​底部面板用于更改Y极限。

图片:在单个Y轴上具有多个输入限制的图表 Screen Shot ** 像这样 Screen Shot

0 个答案:

没有答案