예제 #1
0
파일: demo.py 프로젝트: vvs31415/Phoenix
def _draw2Objects():
    """Sin, Cos, Points, and lines between points"""
    # 100 points sin function, plotted as green dots
    data1 = 2. * np.pi * np.arange(200) / 200.
    data1.shape = (100, 2)
    data1[:, 1] = np.sin(data1[:, 0])
    line1 = wxplot.PolySpline(data1,
                              legend='Green Line',
                              colour='green',
                              width=6,
                              style=wx.PENSTYLE_DOT)

    # 25 points cos function, plotted as red dot-dash with steps.
    data1 = 2. * np.pi * np.arange(50) / 50.
    data1.shape = (25, 2)
    data1[:, 1] = np.cos(data1[:, 0])
    line2 = wxplot.PolyLine(
        data1,
        legend='Red Line',
        colour='red',
        width=2,
        style=wx.PENSTYLE_DOT_DASH,
        drawstyle='steps-post',
    )

    # data points for the 25pt cos function.
    pts2 = wxplot.PolyMarker(
        data1,
        legend='Red Points',
        colour='red',
        size=1.5,
    )

    # A few more points...
    pi = np.pi
    pts = [(0., 0.), (pi / 4., 1.), (pi / 2, 0.), (3. * pi / 4., -1)]
    markers1 = wxplot.PolyMarker(
        pts,
        legend='Cross Hatch Square',
        colour='blue',
        width=3,
        size=6,
        fillcolour='red',
        fillstyle=wx.CROSSDIAG_HATCH,
        marker='square',
    )
    marker_line = wxplot.PolyLine(
        pts,
        legend='Cross Hatch Square',
        colour='blue',
        width=3,
    )

    return wxplot.PlotGraphics([markers1, line1, line2, pts2, marker_line],
                               "Big Markers with Different Line Styles")
예제 #2
0
 def draw(self,x,arry,legd,title,Xtitle,Ytitle,typ='-',axes=None):
     x,arry=transpose(array(x,ndmin=2)),array(arry) # x en vertical
     self.x, self.arry, self.legd, self.title = x, arry, legd, title
     self.Xtitle,self.Ytitle,self.typ = Xtitle, Ytitle,typ
     self.xlog, self.ylog = False, False
     self.lignes = [];cols=['red','blue','green','orange','cyan','black']*5
     # verifier dimensions des vecteurs entree
     if len(shape(x))==1:
         x1 = ones((len(x),1))+0.;
     if len(shape(arry))==1:
         arry1 = ones((len(arry),1))+0.; arry1[:,0]=arry; arry=arry1*1.;ny=1
     else :
         [nt,ny] = shape(arry)
     if axes!=None: a,b,self.xlog,c,d,self.ylog = axes
     x2 = x*1.; arry2 = arry*1.;
     if self.xlog:
         x2[x2<=0.]=1e-7;x2 = log10(x)
     if self.ylog:
         arry2[arry2<=0.]=1e-7;arry2 = log10(arry)
     # creer les lignes
     if ny==1:
         dataL = concatenate([x2,arry2],axis=1)
         if typ=='-': gobj = plot.PolyLine(dataL,colour='red')
         else : gobj = plot.PolyMarker(dataL,colour='red')
         self.lignes.append(gobj)
     else :
         #print 'mydlg',ny,cols,legd
         for i in range(ny):
             dataL = concatenate([x2,arry2[:,i:i+1]],axis=1)
             if typ=='-': gobj = plot.PolyLine(dataL,colour=cols[i],legend=legd[i])
             else : gobj = plot.PolyMarker(dataL,colour=cols[i],legend=legd[i])
             self.lignes.append(gobj)
     drawObj = plot.PlotGraphics(self.lignes,title,Xtitle,Ytitle)
     # limite des axes
     if axes==None or self.xlog:
         xmn = amin(amin(x2)); xmx = amax(amax(x2));
         dmx = xmx-xmn; self.xmx=xmx+dmx/20.; self.xmn=xmn-dmx/20.
     else :
         self.xmn,self.xmx,a,b,c,d = axes
     if axes==None: # or self.ylog:
         ymn = amin(amin(arry2));ymx = amax(amax(arry2));#print 'dlg',ymn,ymx
         dmy = ymx-ymn; self.ymx=ymx+dmy/20.; self.ymn=ymn-dmy/20. 
     else :
         a,b,c,self.ymn,self.ymx,d = axes
     if self.ymn==self.ymx:
         #print arry
         self.ymn=self.ymn*.99;self.ymx=self.ymx*1.01
     #self.ymn = max(self.ymn,0.);self.xmn = max(self.xmn,0.)
     self.cnv.SetEnableLegend(True);self.cnv.SetEnableGrid(True)
     self.cnv.Draw(drawObj,xAxis=(float(self.xmn),float(self.xmx)),
         yAxis=(float(self.ymn),float(self.ymx)))
예제 #3
0
 def plot(self, esp):
     nper = float(self.Limit[0].GetValue())
     tmax = float(self.Limit[1].GetValue())
     Cmax = float(self.Limit[2].GetValue())
     if esp >= 0:  # dessin a partir de Cinj, evt num espece
         per = array(self.periods)
         conc = self.Cinj[:, esp]
         dt, Cmax = per[0], max(float(max(conc)), Cmax)
         if len(per) > 1: dt = per[1] - per[0]
         t2 = self.periods - dt / 2.
     else:  # dessin a partir de modifier plot
         self.choix.SetSelection(0)
         self.Cinj = ones((nper, len(self.especes))) * 1.
         dt = tmax / nper
         t2 = arange(dt / 2., tmax, dt) + 0.
         self.periods = t2 + dt / 2.
         conc = t2 * 0. + Cmax / 2.
     # crer les lignes de l'histogramme
     self.lignes = []
     for i in range(len(t2)):
         t3 = [
             t2[i] - dt / 2., t2[i] - dt / 2., t2[i] + dt / 2.,
             t2[i] + dt / 2.
         ]
         c3 = [0., conc[i], conc[i], 0.]
         dataL = transpose(array([t3, c3]))
         self.lignes.append(plot.PolyLine(dataL))
     # creer les points
     self.data = transpose(array([t2, conc]))
     self.poly = plot.PolyMarker(self.data, marker='circle', colour='red')
     lli = self.lignes * 1
     lli.append(self.poly)
     drawObj = plot.PlotGraphics(lli, "source", "temps", "concentration")
     self.cnv.Draw(drawObj, xAxis=(0, tmax), yAxis=(0, Cmax * 1.1))
     self.Cmax = Cmax
예제 #4
0
 def OnScatter(self, event):
     frm = wx.Frame(self, -1, 'scatter', size=(600,450))
     client = plot.PlotCanvas(frm)
     markers = plot.PolyMarker(self.data, legend='', colour='pink', marker='triangle_down', size=1)
     gc = plot.PlotGraphics([markers], 'Scatter Graph', 'X Axis', 'Y Axis')
     client.Draw(gc, xAxis=(0,15), yAxis=(0,15))
     frm.Show(True)
예제 #5
0
파일: scatter.py 프로젝트: tmszi/grass
    def CreatePlotList(self):
        """Make list of elements to plot"""
        # graph the cell value, frequency pairs for the histogram
        self.plotlist = []

        for rpair in self.rasterList:
            if ("datalist" not in self.raster[rpair]
                    or self.raster[rpair]["datalist"] is None):
                continue

            if len(self.raster[rpair]["datalist"]) > 0:
                col = wx.Colour(
                    self.raster[rpair]["pcolor"][0],
                    self.raster[rpair]["pcolor"][1],
                    self.raster[rpair]["pcolor"][2],
                    255,
                )
                scatterpoints = plot.PolyMarker(
                    self.raster[rpair]["datalist"],
                    legend=" " + self.raster[rpair]["plegend"],
                    colour=col,
                    size=self.raster[rpair]["psize"],
                    fillstyle=self.ptfilldict[self.raster[rpair]["pfill"]],
                    marker=self.raster[rpair]["ptype"],
                )

                self.plotlist.append(scatterpoints)

        return self.plotlist
예제 #6
0
    def __init__(self, data, origData, yieldCurve):
        self.frame1 = wx.Frame(None, title="Analyttlic", id=-1, size=(800, 600))
        self.panel1 = wx.Panel(self.frame1)
        #self.panel1.SetBackgroundColour("yellow")

        # mild difference between wxPython26 and wxPython28
        if wx.VERSION[1] < 7:
            plotter = plot.PlotCanvas(self.panel1, size=(800, 600))
        else:
            plotter = plot.PlotCanvas(self.panel1)
            plotter.SetInitialSize(size=(800, 600))

        # enable the zoom feature (drag a box around area of interest)
        plotter.SetEnableZoom(True)


        # list of (x,y) data point tuples
        # data = [(1,2), (2,3), (3,5), (4,6), (5,8), (6,8), (12,10), (13,4)]

        # draw points as a line
        line = plot.PolyLine(data, colour='red', width=1)
        origLine = plot.PolyLine(origData, colour='blue', width=1)  
        # also draw markers, default colour is black and size is 2
        # other shapes 'circle', 'cross', 'square', 'dot', 'plus'
        marker = plot.PolyMarker(origData, marker='cross')
        yieldLine = plot.PolyLine(yieldCurve, colour='green', width=1)
        # set up text, axis and draw
        gc = plot.PlotGraphics([line, origLine, marker, yieldLine], 'Forward Rates Curve', 'Time (years)', 'Forward Rate (%)')
        plotter.Draw(gc, xAxis=(0,20), yAxis=(0,20))

        self.frame1.Show(True)
예제 #7
0
    def OnConvergence(self, event):
        m1 = 0
        m2 = 0
        newdata = []
        #self.get_rtt_data()
        source = self.srctxt.GetValue()
        infoh = self.infotxt.GetValue()
        obj = graphs.Plot()
        newdata = obj.convergence(self.list, source, infoh)
        firstitem = []
        for item in newdata:
            firstitem.append(item[0])

        if firstitem:
            maxi = max(firstitem)
            mini = min(firstitem)
        frm = wx.Frame(self, -1, 'Look@MLKademlia', size=(600, 450))
        client = plot.PlotCanvas(frm)
        client.SetEnableZoom(True)
        line = plot.PolyLine(newdata, legend='', colour='red', width=1)
        marker = plot.PolyMarker(newdata,
                                 marker='triangle',
                                 colour='blue',
                                 size=1,
                                 width=1)
        gc = plot.PlotGraphics([line, marker], 'Lookup Convergence', 'Time(s)',
                               'Log Distance from Infohash')
        client.Draw(gc, xAxis=(mini - 1, maxi + 1), yAxis=(100, 180))
        #client.Draw(gc)
        frm.Show(True)
예제 #8
0
    def __init__(self):

        self.frame1 = wx.Frame(None,
                               title="wx.lib.plot",
                               id=-1,
                               size=(410, 340))
        self.panel1 = wx.Panel(self.frame1)
        self.panel1.SetBackgroundColour("yellow")
        if wx.VERSION[1] < 7:
            plotter = plot.PlotCanvas(self.panel1, size=(400, 300))
        else:
            plotter = plot.PlotCanvas(self.panel1)
            plotter.SetInitialSize(size=(400, 300))
        plotter.SetEnableZoom(True)
        data = [(1, 2), (2, 3), (3, 5), (4, 6), (5, 8), (6, 8), (12, 10),
                (13, 4)]
        # draw points as a line
        line = plot.PolyLine(data, colour='red', width=1)

        # also draw markers, default colour is black and size is 2

        # other shapes 'circle', 'cross', 'square', 'dot', 'plus'
        marker = plot.PolyMarker(data, marker='triangle')

        # set up text, axis and draw
        gc = plot.PlotGraphics([line, marker], 'Line/Marker Graph', 'x axis',
                               'y axis')
        plotter.Draw(gc, xAxis=(0, 15), yAxis=(0, 15))

        self.frame1.Show(True)
예제 #9
0
    def CreatePlotList(self):
        """Make list of elements to plot
        """
        # graph the cell value, frequency pairs for the histogram
        self.plotlist = []

        for rpair in self.rasterList:
            if 'datalist' not in self.raster[rpair] or \
                self.raster[rpair]['datalist'] is None:
                continue

            if len(self.raster[rpair]['datalist']) > 0:
                col = wx.Colour(self.raster[rpair]['pcolor'][0],
                                self.raster[rpair]['pcolor'][1],
                                self.raster[rpair]['pcolor'][2], 255)
                scatterpoints = plot.PolyMarker(
                    self.raster[rpair]['datalist'],
                    legend=' ' + self.raster[rpair]['plegend'],
                    colour=col,
                    size=self.raster[rpair]['psize'],
                    fillstyle=self.ptfilldict[self.raster[rpair]['pfill']],
                    marker=self.raster[rpair]['ptype'])

                self.plotlist.append(scatterpoints)

        return self.plotlist
예제 #10
0
	def OnPlotScatter(self, event=None):

		data = self.data

		## sans fusion
		if isinstance(data, list):
			if self.normalize:
				m = max(map(lambda a: a[1], data))
				data = map(lambda b: (b[0], b[1]/m), data)
			markers = plot.PolyMarker(data, colour = LColour[0], marker = Markers[0], size = 1)
			line = plot.PolyLine(data, legend = 'Port 0 %s'%self.legend, colour = LColour[0], width = 1)
			self.gc = plot.PlotGraphics([line, markers], self.title, self.xLabel, self.yLabel)
			xMin,xMax,yMin,yMax = get_limit(data)

		##avec fusion (voir attribut _fusion de QuickScope)
		else:
			L=[]
			xMin, xMax, yMin, yMax = 0,0,0,0
			data_list = data.values()
			for ind,d in enumerate(data_list):
				try:
					c = LColour[ind]
				except IndexError:
					c = LColour[0]

				try:
					m = Markers[ind]
				except IndexError:
					m = Markers[0]

				if self.normalize:
					m = max(map(lambda a: a[1], d))
					d = map(lambda b: (b[0], b[1]/m), d)

				L.append(plot.PolyLine(d, legend = 'Port 0 %s'%self.legend, colour=c, width=1))
				L.append(plot.PolyMarker(d, colour=c, marker=m, size=1))

				a,b,c,d = get_limit(d)

				if a < xMin: xMin=a
				if b > xMax: xMax= b
				if c < yMin: yMin=c
				if d > yMax:yMax=d

			self.gc = plot.PlotGraphics(L, self.title, self.xLabel, self.yLabel)

		self.client.Draw(self.gc, xAxis = (float(xMin),float(xMax)), yAxis = (float(yMin),float(yMax)))
예제 #11
0
파일: demo.py 프로젝트: vvs31415/Phoenix
def _draw1Objects():
    """Sin, Cos, and Points"""
    # 100 points sin function, plotted as green circles
    data1 = 2. * np.pi * np.arange(-200, 200) / 200.
    data1.shape = (200, 2)
    data1[:, 1] = np.sin(data1[:, 0])
    markers1 = wxplot.PolyMarker(
        data1,
        legend='Green Markers',
        colour='green',
        marker='circle',
        size=1,
    )

    # 50 points cos function, plotted as red line and markers
    data1 = 2. * np.pi * np.arange(-100, 100) / 100.
    data1.shape = (100, 2)
    data1[:, 1] = np.cos(data1[:, 0])
    lines = wxplot.PolySpline(data1, legend='Red Line', colour='red')
    markers3 = wxplot.PolyMarker(
        data1,
        legend='Red Dot',
        colour='red',
        marker='circle',
        size=1,
    )

    # A few more points...
    pi = np.pi
    pts = [(0., 0.), (pi / 4., 1.), (pi / 2, 0.), (3. * pi / 4., -1)]
    markers2 = wxplot.PolyMarker(
        pts,
        legend='Cross Legend',
        colour='blue',
        marker='cross',
    )
    line2 = wxplot.PolyLine(pts, drawstyle='steps-post')

    return wxplot.PlotGraphics(
        [markers1, lines, markers3, markers2, line2],
        "Graph Title",
        "X Axis",
        "Y Axis",
    )
예제 #12
0
    def Update(self, data):
        for index in range(30):
            self.data[index]=(self.data[index][0],self.data[index+1][1])

        self.data[30] = (30,data)
        
        self.markers = wxPlot.PolyMarker(self.data, legend='', colour=self.color, marker='circle', size=1)
        self.gc = wxPlot.PlotGraphics([self.markers], self.name, 'Time', 'Watt')
        self.client.Draw(self.gc, xAxis=(0,30), yAxis=(-5,300))
        self.Show(True)
예제 #13
0
    def plot(self, data, markerPoint, axis, max_y):
        line = plot.PolyLine(data, colour='red', width=1)
        marker = plot.PolyMarker([markerPoint])
        # set up text, axis and draw
        gc = plot.PlotGraphics([line, marker], '', '', '')

        max_y = math.fabs(max_y)
        max_y += 0.5

        self.plotter.Draw(gc, yAxis=(-1.5,1.5), xAxis=(-max_y,max_y))
예제 #14
0
    def OnQandR(self, event):

        frm = wx.Frame(self, -1, 'Look@MLKademlia', size=(600, 450))
        client = plot.PlotCanvas(frm)
        client.SetEnableZoom(True)
        source = self.srctxt.GetValue()
        infoh = self.infotxt.GetValue()
        type = self.typebox.GetValue()
        thisclick = event.GetEventObject()

        obj = graphs.Plot()

        qts, rts = obj.timestamps(self.list, source, infoh, type)
        if not qts:
            print 'no queries found'
            assert 0
        a = min(qts)
        b = max(qts)
        minimum = a[1] - 1
        maximum = b[1] + 1

        client.SetEnableLegend(True)
        client.SetEnableGrid(True)
        markers1 = plot.PolyMarker(qts,
                                   legend='Query',
                                   colour='red',
                                   marker='circle',
                                   size=1,
                                   width=1)
        markers2 = plot.PolyMarker(rts,
                                   legend='Response',
                                   colour='blue',
                                   marker='triangle',
                                   size=1,
                                   width=1)

        gc = plot.PlotGraphics([markers1, markers2], 'Queries and Responses',
                               'Queries and Responses', 'Time(s)')

        client.Draw(gc, xAxis=(0, len(qts)), yAxis=(minimum, maximum))

        frm.Show(True)
예제 #15
0
def _draw3Objects():
    """Various Marker Types"""
    markerList = ['circle', 'dot', 'square', 'triangle', 'triangle_down',
                  'cross', 'plus', 'circle']
    m = []
    for i in range(len(markerList)):
        m.append(wxplot.PolyMarker([(2 * i + .5, i + .5)],
                                   legend=markerList[i],
                                   colour='blue',
                                   marker=markerList[i])
                                   )
    return wxplot.PlotGraphics(m,
                               title="Selection of Markers",
                               xLabel="Minimal Axis",
                               yLabel="No Axis")
예제 #16
0
    def __init__(self, name,pos, size, color):
        wx.Frame.__init__(self, None, -1, name, pos, size) 
        self.name = name
        self.color = color
        self.data = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
        for index in range(31):
            self.data[index]=(index,0)

        self.client = wxPlot.PlotCanvas(self)
        self.markers = wxPlot.PolyMarker(self.data, legend='', colour=self.color, marker='circle', size=1)
        self.gc = wxPlot.PlotGraphics([self.markers], name, 'Time', 'Watt')
        self.client.Draw(self.gc, xAxis=(0,30), yAxis=(-5,300))
        self.Show(True)

        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
예제 #17
0
def MyDataObject():
    # 50 个点的sin函数,用蓝色圆点表示
    data1 = 2. * numpy.pi * numpy.arange(100) / 100.
    data1.shape = (50, 2)
    data1[:, 1] = numpy.sin(data1[:, 0])
    markers = wxPyPlot.PolyMarker(data1, legend='Green Markers', colour='blue', marker='circle', size=1)

    # 50个点的cos函数,用红色表示
    data2 = 2. * numpy.pi * numpy.arange(100) / 100.
    data2.shape = (50, 2)
    data2[:, 1] = numpy.cos(data2[:, 0])
    lines = wxPyPlot.PolySpline(data2, legend='Red Line', colour='red')

    GraphTitle = "Plot Data(Sin and Cos)"

    return wxPyPlot.PlotGraphics([markers, lines], GraphTitle, "X Axis", "Y Axis")
예제 #18
0
    def CreatePlotList(self):
        """Create a plot data list from transect datalist and
        transect segment endpoint coordinates.
        """
        # graph the distance, value pairs for the transect
        self.plotlist = []

        # Add segment marker points to plot data list
        if len(self.seglist) > 0:
            self.ppoints = plot.PolyMarker(
                self.seglist,
                legend=" " + self.properties["marker"]["legend"],
                colour=wx.Colour(
                    self.properties["marker"]["color"][0],
                    self.properties["marker"]["color"][1],
                    self.properties["marker"]["color"][2],
                    255,
                ),
                size=self.properties["marker"]["size"],
                fillstyle=self.ptfilldict[self.properties["marker"]["fill"]],
                marker=self.properties["marker"]["type"],
            )
            self.plotlist.append(self.ppoints)

        # Add profile distance/elevation pairs to plot data list for each
        # raster profiled
        for r in self.rasterList:
            col = wx.Colour(
                self.raster[r]["pcolor"][0],
                self.raster[r]["pcolor"][1],
                self.raster[r]["pcolor"][2],
                255,
            )
            self.raster[r]["pline"] = plot.PolyLine(
                self.raster[r]["datalist"],
                colour=col,
                width=self.raster[r]["pwidth"],
                style=self.linestyledict[self.raster[r]["pstyle"]],
                legend=self.raster[r]["plegend"],
            )

            self.plotlist.append(self.raster[r]["pline"])

        if len(self.plotlist) > 0:
            return self.plotlist
        else:
            return None
예제 #19
0
    def CreatePlotList(self):
        """Create a plot data list from transect datalist and
            transect segment endpoint coordinates.
        """
        # graph the distance, value pairs for the transect
        self.plotlist = []

        # Add segment marker points to plot data list
        if len(self.seglist) > 0:
            self.ppoints = plot.PolyMarker(
                self.seglist,
                legend=' ' + self.properties['marker']['legend'],
                colour=wx.Colour(
                    self.properties['marker']['color'][0],
                    self.properties['marker']['color'][1],
                    self.properties['marker']['color'][2],
                    255),
                size=self.properties['marker']['size'],
                fillstyle=self.ptfilldict[
                    self.properties['marker']['fill']],
                marker=self.properties['marker']['type'])
            self.plotlist.append(self.ppoints)

        # Add profile distance/elevation pairs to plot data list for each
        # raster profiled
        for r in self.rasterList:
            col = wx.Colour(self.raster[r]['pcolor'][0],
                            self.raster[r]['pcolor'][1],
                            self.raster[r]['pcolor'][2],
                            255)
            self.raster[r]['pline'] = plot.PolyLine(
                self.raster[r]['datalist'],
                colour=col, width=self.raster[r]['pwidth'],
                style=self.linestyledict[self.raster[r]['pstyle']],
                legend=self.raster[r]['plegend'])

            self.plotlist.append(self.raster[r]['pline'])

        if len(self.plotlist) > 0:
            return self.plotlist
        else:
            return None
예제 #20
0
파일: demo.py 프로젝트: vvs31415/Phoenix
def _draw4Objects():
    """25,000 point line and markers"""
    # Points
    data1 = np.random.normal(loc=7.5e5, scale=70000, size=50000)
    data1.shape = (25000, 2)
    markers2 = wxplot.PolyMarker(
        data1,
        legend='Dots',
        colour='blue',
        marker='square',
        size=1,
    )

    # Line
    data1 = np.arange(5e5, 1e6, 10)
    data1.shape = (25000, 2)
    line1 = wxplot.PolyLine(data1, legend='Wide Line', colour='green', width=4)

    return wxplot.PlotGraphics([markers2, line1], "25,000 Points", "Value X",
                               "")
예제 #21
0
    def OnPlotScatter(self, event):

        #if self.timer.IsRunning():
        ### unbinding paint event
        if self.type != "PlotScatter":
            self.type = "PlotScatter"
            self.Unbind(wx.EVT_PAINT)
            self.Bind(wx.EVT_PAINT, getattr(self, "On%s" % self.type))

        ## sans fusion
        if self.iport is not None:

            data = self.atomicModel.results[self.iport]

            if self.normalize:
                m = max(map(lambda a: a[1], data))
                data = map(lambda b: (b[0], b[1] / m), data)

            markers = plot.PolyMarker(data,
                                      colour=LColour[0],
                                      marker=Markers[0],
                                      size=1)
            markers = plot.PolyLine(data,
                                    legend='Port 0 (%s)' %
                                    self.atomicModel.getBlockModel().label,
                                    colour=LColour[0],
                                    width=1)
            self.gc = plot.PlotGraphics([line, markers], self.title,
                                        self.xLabel, self.yLabel)
            xMin, xMax, yMin, yMax = get_limit(data)

        ##avec fusion (voir attribut _fusion de QuickScope)
        else:

            data = self.atomicModel.results
            label = self.atomicModel.getBlockModel().label

            L = []
            xMin, xMax = 0, 0
            yMin, yMax = 0, 0

            data_list = data.values()
            for ind, d in enumerate(data_list):
                #ind = data.values().index(d)
                try:
                    c = LColour[ind]
                except IndexError:
                    c = LColour[0]

                try:
                    m = Markers[ind]
                except IndexError:
                    m = Markers[0]

                if self.normalize:
                    m = max(map(lambda a: a[1], d))
                    d = map(lambda b: (b[0], b[1] / m), d)

                L.append(plot.PolyLine(d, colour=c, width=1))
                L.append(
                    plot.PolyMarker(d,
                                    legend='Port %s (%s)' %
                                    (str(data.keys()[ind]), label),
                                    colour=c,
                                    marker=m,
                                    size=1))

                a, b, c, d = get_limit(d)

                if a < xMin: xMin = a
                if b > xMax: xMax = b
                if c < yMin: yMin = c
                if d > yMax: yMax = d

            self.gc = plot.PlotGraphics(L, self.title, self.xLabel,
                                        self.yLabel)

        try:
            self.client.Draw(self.gc,
                             xAxis=(float(xMin), float(xMax)),
                             yAxis=(float(yMin), float(yMax)))
        except Exception:
            sys.stdout.write(_("Error trying to plot"))

        if self.sim_thread is None or not self.sim_thread.isAlive():
            self.timer.Stop()
예제 #22
0
    def OnDropDown(self, e=None):
        """ Plot the parameter selected in WXDropdown
            Uses info stored in self.PlotParms and self.InfoClass
        """
        if self.parent.notebook.GetPageCount() == 0 or self.Page is None:
            self.canvas.Clear()
            return

        # Get valid pages
        strFull = self.WXTextPages.GetValue()
        try:
            PageNumbers = misc.parseString2Pagenum(self,
                                                   strFull,
                                                   nodialog=True)
        except:
            PageNumbers = self.PageNumbers
        else:
            self.PageNumbers = PageNumbers

        # Get plot parameters
        DDselid = self.WXDropdown.GetSelection()
        #[label, key] = self.PlotParms[DDselid]
        label = self.PlotParms[DDselid]
        # Get potential pages
        pages = list()
        for i in np.arange(self.parent.notebook.GetPageCount()):
            Page = self.parent.notebook.GetPage(i)
            if Page.corr.fit_model.id == self.Page.corr.fit_model.id:
                # Only pages with same modelid
                if int(Page.counter.strip("#: ")) in PageNumbers:
                    # Only pages selected in self.WXTextPages
                    pages.append(Page)
        plotcurve = list()
        for page in pages:
            pllabel, pldata = self.GetListOfPlottableParms(page=page,
                                                           return_values=True)
            # Get the labels and make a plot of the parameters
            if len(pllabel) - 1 >= DDselid and pllabel[DDselid] == label:
                x = int(page.counter.strip("#: "))
                y = pldata[DDselid]
                plotcurve.append([x, y])
            else:
                # try to get the label by searching for the first
                # instance
                for k in range(len(pllabel)):
                    if pllabel[k] == label:
                        x = int(page.counter.strip("#: "))
                        y = pldata[k]
                        plotcurve.append([x, y])
        # Prepare plotting
        self.canvas.Clear()
        linesig = plot.PolyMarker(plotcurve, size=1.5, marker='circle')
        plotlist = [linesig]
        # average line
        try:
            avg = np.average(np.array(plotcurve)[:, 1])
            maxpage = int(np.max(np.array(plotcurve)[:, 0]) + 1)
            minpage = int(np.min(np.array(plotcurve)[:, 0]) - 1)
        except:
            minpage = 0
            maxpage = 0
            self.WXavg.SetValue("-")
            self.WXsd.SetValue("-")
        else:
            # Plot data
            plotavg = [[0.5, avg], [maxpage + .5, avg]]
            #lineclear = plot.PolyLine(plotavg, colour="black")
            lineclear = plot.PolyMarker(plotavg, colour="black")
            plotlist.append(lineclear)
            # Update Text control
            self.WXavg.SetValue(str(avg))
            self.WXsd.SetValue(str(np.std(np.array(plotcurve)[:, 1])))
        # Draw
        # This causes a memory leak after this function has been
        # called several times with the same large data set.
        # This goes away if only linesig OR lineclear are plotted.
        #
        #graphics = plot.PlotGraphics(plotlist,
        #                             xLabel='page number',
        #                             yLabel=label)
        graphics = plot.PlotGraphics([linesig],
                                     xLabel='page number',
                                     yLabel=label)

        # Correctly set x-axis
        minticks = 2
        self.canvas.SetXSpec(max(maxpage - minpage, minticks))
        self.canvas.Draw(graphics, xAxis=(minpage, maxpage))
예제 #23
0
    def wykres(self, x, y, liczba_wezlow, zakres1, zakres2, x_min, x_max, Re,
               Podzial, odwroc, wezly_rownomiernie):

        zakres1 = float(self.text_ctrl_zakres1.GetValue())
        zakres2 = float(self.text_ctrl_zakres2.GetValue())
        x_min = float(self.text_ctrl_x_min.GetValue())
        x_max = float(self.text_ctrl_x_max.GetValue())
        Podzial = float(self.text_ctrl_Podzial.GetValue())
        liczba_wezlow = int(self.spin_ctrl_ilosc_wezlow.GetValue())
        wezly_rownomiernie = int(self.spin_ctrl_wezly_rownomiernie.GetValue())
        Przesuniecie = float(self.text_ctrl_Przesuniecie.GetValue())

        x[0] = int(self.spin_ctrl_x1.GetValue())
        x[1] = int(self.spin_ctrl_x2.GetValue())
        x[2] = int(self.spin_ctrl_x3.GetValue())
        x[3] = int(self.spin_ctrl_x4.GetValue())
        x[4] = int(self.spin_ctrl_x5.GetValue())
        x[5] = int(self.spin_ctrl_x6.GetValue())

        y[0] = float(self.text_ctrl_y1.GetValue())
        y[1] = float(self.text_ctrl_y2.GetValue())
        y[2] = float(self.text_ctrl_y3.GetValue())
        y[3] = float(self.text_ctrl_y4.GetValue())
        y[4] = float(self.text_ctrl_y5.GetValue())
        y[5] = float(self.text_ctrl_y6.GetValue())

        odwroc = int(self.Check_odwroc.IsChecked())

        wielomian_szostego_stopnia(x, y, y_plus, wezel, liczba_wezlow,
                                   wspolrzedne_wezlow, x_min, x_max, Re,
                                   Podzial, odwroc, wezly_rownomiernie,
                                   Przesuniecie)

        zakres1_n = zakres_wykresu(liczba_wezlow, wspolrzedne_wezlow, zakres1)
        zakres2_n = zakres_wykresu(liczba_wezlow, wspolrzedne_wezlow, zakres2)

        liczba_wezlow_w_zakresie = zakres2_n - zakres1_n
        #self.zakres_wyswietlania2.SetLabel(str(liczba_wezlow_w_zakresie))

        #self.figure = matplotlib.figure.Figure()
        #self.y_plus_n = self.figure.add_subplot(2,2,1)
        #self.y_plus_x = self.figure.add_subplot(2,2,2)
        #self.y_plus_x2 = self.figure.add_subplot(2,1,2)

        #self.y_plus_n.plot(wezel[0:liczba_wezlow],y_plus[0:liczba_wezlow])

        #self.y_plus_x.plot(wspolrzedne_wezlow[0:liczba_wezlow],y_plus[0:liczba_wezlow])

        #self.y_plus_x2.plot(wspolrzedne_wezlow[zakres1_n:zakres2_n],y_plus[zakres1_n:zakres2_n],marker='o', color='r')

        #self.window_2 = FigureCanvas(self, -1, self.figure)
        self.data1 = []

        for i in range(0, liczba_wezlow):
            f = (wezel[i], y_plus[i])
            self.data1.append(f)

        self.figure = plot.PlotCanvas(self.window_2)
        self.figure.SetInitialSize(size=(310, 300))
        self.figure.SetPosition((0, 0))

        self.line = plot.PolyLine(self.data1, colour='red', width=2)
        self.gc = plot.PlotGraphics([self.line])
        self.figure.Draw(self.gc)

        ################################################33

        self.data2 = []

        for i in range(0, liczba_wezlow):
            f = (wspolrzedne_wezlow[i], y_plus[i])
            self.data2.append(f)

        self.figure2 = plot.PlotCanvas(self.window_2)
        self.figure2.SetInitialSize(size=(310, 300))
        self.figure2.SetPosition((310, 0))

        self.line2 = plot.PolyLine(self.data2, colour='red', width=2)
        self.gc = plot.PlotGraphics([self.line2])
        self.figure2.Draw(self.gc)

        ################################################33

        self.data3 = []

        for i in range(zakres1_n, zakres2_n):
            f = (wspolrzedne_wezlow[i], y_plus[i])
            self.data3.append(f)

        self.figure3 = plot.PlotCanvas(self.window_2)
        self.figure3.SetInitialSize(size=(640, 220))
        self.figure3.SetPosition((0, 300))

        self.line3 = plot.PolyLine(self.data3, colour='red', width=2)
        self.punkty = plot.PolyMarker(self.data3,
                                      legend='',
                                      colour='blue',
                                      marker='circle',
                                      size=1)
        self.gc = plot.PlotGraphics([self.line3, self.punkty])
        self.figure3.Draw(self.gc)

        del self.data1, self.data2, self.data3

        self.__set_properties()
        self.__do_layout()
예제 #24
0
    def plot_data(self):
        """Plot data.
		
		Parameters:
		-----------
		self.Full_E : vector of floats 
			photon energies at which the real and imaginary scattering factor data will be plotted.
		self.Imaginary_Spectrum : Array of float 
			polynomial coefficients that can be evaluated to give the values of the imaginary scattering factors.
		self.KK_Real_Spectrum : vector of float 
			the values of the real scattering factors.

		Returns
		-------
		The GUI is updated, but nothing is returned.
		"""
        logger.info("plotting data")
        # List of things to plot
        plotlist = []
        # get initial guess at X limits
        X_min = 0
        X_max = 30000
        Y_max = 1
        Y_min = 0
        if self.NearEdgeData is not None:
            X_min = self.NearEdgeData[0, 0]
            X_max = self.NearEdgeData[-1, 0]
        if self.SpliceText1.GetValue() != "Start":
            X_min = float(self.SpliceText1.GetValue())
        if self.SpliceText2.GetValue() != "End":
            X_max = float(self.SpliceText2.GetValue())
        if self.Imaginary_Spectrum is not None:
            if self.Stoichiometry is not None:
                scale = sum([Z * count for Z, count in self.Stoichiometry])
            else:
                scale = 1.
            Im_energies, Im_values = data.coeffs_to_linear(
                self.Full_E, self.Imaginary_Spectrum, 0.001 * scale)
            plotlist.append(
                plot.PolyLine(list(zip(Im_energies, Im_values)),
                              colour='black',
                              width=1))

            # get Y limits
            if self.splice_ind is None:
                Y_max = max(Im_values)
                Y_min = min(Im_values)
            else:
                Y_max = max(Im_values[self.splice_ind[0]:self.splice_ind[1]])
                Y_min = min(Im_values[self.splice_ind[0]:self.splice_ind[1]])
        if self.NearEdgeData is not None:
            Y_max = max(self.NearEdgeData[:, 1])
            Y_min = min(self.NearEdgeData[:, 1])
            plotlist.append(
                plot.PolyMarker(list(
                    zip(self.NearEdgeData[:, 0], self.NearEdgeData[:, 1])),
                                colour='blue',
                                marker='plus',
                                size=1))

        if self.splice_ind is not None:
            splice_values = data.coeffs_to_ASF(
                self.Full_E[self.splice_ind], self.Imaginary_Spectrum[[
                    self.splice_ind[0],
                    min(self.splice_ind[1],
                        self.Imaginary_Spectrum.shape[0] - 1)
                ]])
            plotlist.append(
                plot.PolyMarker(list(
                    zip(self.Full_E[self.splice_ind], splice_values)),
                                colour='red',
                                marker='cross',
                                size=1))

        if self.raw_file is not None and self.Imaginary_Spectrum is None:
            logger.info("plot raw data only")
            plotlist.append(
                plot.PolyLine(self.NearEdgeData, colour='blue',
                              width=1))  # User data
            if self.asf_bg is not None:
                plotlist.append(
                    plot.PolyMarker(
                        self.total_asf[self.asf_bg[0][0]:self.asf_bg[0][1],
                                       [0, 2]],
                        colour='red',
                        marker='cross',
                        size=1))
                plotlist.append(
                    plot.PolyLine(self.asf_bg[1], colour='red', width=1))

            # Real part
            #plotlist.append(plot.PolyLine(self.total_asf[:, [0, 1]], colour='black', width=1))
        if self.KK_Real_Spectrum is not None:
            if self.splice_ind is None:
                Y_max = max(self.KK_Real_Spectrum)
                Y_min = min(self.KK_Real_Spectrum)
            else:
                Y_max = max(
                    Y_max,
                    max(self.KK_Real_Spectrum[self.splice_ind[0]:self.
                                              splice_ind[1]]))
                Y_min = min(
                    Y_min,
                    min(self.KK_Real_Spectrum[self.splice_ind[0]:self.
                                              splice_ind[1]]))
            plotlist.append(
                plot.PolyLine(list(zip(self.Full_E, self.KK_Real_Spectrum)),
                              colour='green',
                              width=1))

        # Expand plotting limits for prettiness
        window_width = X_max - X_min
        X_max = X_max + window_width * 0.1
        X_min = max(X_min - window_width * 0.1, 0)
        window_Im_height = Y_max - Y_min
        window_Re_height = Y_max - Y_min
        Y_max = Y_max + window_Im_height * 0.1
        Y_min = Y_min - window_Im_height * 0.1
        Y_max = Y_max + window_Re_height * 0.1
        Y_min = Y_min - window_Re_height * 0.1
        # set up text, axis and draw
        #print plotlist
        #print X_min, X_max, Y_min, Y_max
        self.PlotAxes.Draw(plot.PlotGraphics(plotlist, '', 'Energy (eV)',
                                             'Magnitude'),
                           xAxis=(X_min, X_max),
                           yAxis=(0, Y_max))
예제 #25
0
 def OnPlot(self, event):
     if self.plot_on == 1:
         self.plot.Destroy()  # destroy old plot
     frm = wx.Frame(self, -1, 'simSpectrum_plot.txt', size=(600, 450))
     #--------  read simSpectrum_table.txt and fill cb0  ----------------
     self.data2 = []
     self.fyList = []  # Empty ComboBox textfield and refill below
     inputfile = 'simSpectrum_table.txt'
     f = open(inputfile)
     lines = f.readlines()
     yMin = 1e6
     yMax = -1e6
     for line in lines:
         if line.startswith('#'): continue
         words = line.split()
         name = words[0]
         energy = int(round(float(words[1])))  # round up to int
         inten = words[2]
         inten = inten[:7]
         tag = words[0] + '(' + str(energy) + 'eV)= ' + inten
         self.fyList.append(tag)  # add to ComboBox textfield
         self.data2.append(
             (energy, float(inten)))  # data2 for secondary plot
         if (float(inten) > yMax): yMax = float(inten)
     f.close()
     #self.cbLINES.Destroy()          # Destroy ComboBox
     #self.cbLINES = wx.ComboBox(self, 3, 'emission lines', (120, 30), (165, 10), self.fyList, wx.CB_DROPDOWN)
     self.cbLINES.Clear(
     )  # use these two lines instead of above 2, 8/27/2010
     self.cbLINES.AppendItems(self.fyList)
     #Recreate ComboBox with updated list
     #--------  Reload simSpectrum_plot.txt'  ----------------
     self.data = []
     inputfile = 'simSpectrum_plot.txt'
     f = open(inputfile)
     lines = f.readlines()
     self.xMin = 1e6
     self.xMax = -1e6
     self.yMin = 1e6
     self.yMax = -1e6
     for line in lines:
         if line.startswith('#'): continue
         words = line.split()
         xx = float(words[0])
         if self.xMin > xx: self.xMin = xx
         if self.xMax <= xx: self.xMax = xx
         yy = float(words[1])
         if self.yMin > yy: self.yMin = yy
         if self.yMax <= yy: self.yMax = yy
         self.data.append((xx, yy))
     f.close()
     factor = (self.yMax / yMax)
     for (ix, ii) in enumerate(self.data2):
         self.data2[ix] = (ii[0], ii[1] * factor)
     eV0 = self.input.eV0
     Atoms = self.input.Atoms
     xsw = self.input.xsw
     temp = ''
     for nn in Atoms:
         temp = temp + '/' + nn
     temp = temp[1:]
     title = str(eV0) + 'eV, ' + temp
     if xsw == 1: title += ', xsw'
     #------------------------------------------------
     client = plot.PlotCanvas(frm)
     line = plot.PolyLine(self.data, legend='', colour='red', width=1)
     line2 = plot.PolyMarker(self.data2,
                             legend='',
                             colour='blue',
                             marker='circle',
                             size=0.8)
     gc = plot.PlotGraphics([line, line2], title, 'energy (eV)',
                            'intensity (total count=100k)')
     client.setLogScale((False, True))
     client.Draw(gc,
                 xAxis=(self.xMin, self.xMax),
                 yAxis=(self.yMin, self.yMax))
     frm.Show(True)
     self.plot_on = 1  # to delete the old plot.
     self.plot = frm