|
From: Sherif A. <she...@lo...> - 2009-03-18 23:22:47
|
####################################################################### # # $Id: PlotSmith.py,v 1.3 2008/08/18 06:13:14 lorenz Exp $ # # Copyright (C) 2004-2008 Petr Lorenz # All rights reserved. # # ##### BEGIN LICENSE BLOCK ##### # # Version: MPL 1.1 / GPL 2.0 / LGPL 2.1 # # The contents of this file are subject to the Mozilla Public License # Version 1.1 (the "License"); you may not use this file except in # compliance with the License. You may obtain a copy of the License at # http://www.mozilla.org/MPL/ # # Software distributed under the License is distributed on an "AS IS" # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the # License for the specific language governing rights and limitations # under the License. # # The Original Code is Petr Lorenz emGine Graphical User Interface (GUI). # # The Initial Developer of the Original Code is Petr Lorenz. # Portions created by the Initial Developer are Copyright (C) 2004-2008. # All Rights Reserved. # # Contributor(s): Sherif Sayed Ahmed # # Alternatively, the contents of this file may be used under the terms of # either the GNU General Public License Version 2 or later (the "GPL"), or the # GNU Lesser General Public License Version 2.1 or later (the "LGPL"), in which # case the provisions of the GPL or the LGPL are applicable instead of those # above. If you wish to allow use of your version of this file only under the # terms of either the GPL or the LGPL and not to allow others to use your # version of this file under the MPL, indicate your decision by deleting the # provisions above and replace them with the notice and other provisions # required by the GPL or LGPL. If you do not delete the provisions above, a # recipient may use your version of this file under the terms of any one of the # MPL License, the GPL or the LGPL. # # ##### END LICENSE BLOCK ##### # ####################################################################### # # $Log: PlotSmith.py,v $ # Revision 1.3 2008/08/18 06:13:14 lorenz # Changes related to 0.7.5 testing version: # - new docking window manager # - changed calculation of S-Parameters # - triangulation of polygons # # Revision 1.2 2008-04-07 05:09:35 lorenz # Smith diagram integration. # # Revision 1.1 2008-03-28 06:18:27 lorenz # Initial commit. # # ####################################################################### # # March 2008 # # 2D plotting with matplotlib # import wx from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas from matplotlib.backends.backend_wx import NavigationToolbar2Wx from matplotlib.figure import Figure ##import XYDataSource # to calculate the phases from numpy import * ##def phase(num): ## return math.atan2(num.imag, num.real) ## class PlotSmith: def __init__(self, master): self.hold = 0 # create the matplotlib-based Plot self.figure = Figure(facecolor = 'w') self.figure_canvas = FigureCanvas(master, -1, self.figure) self.hide() # hide the widget def clear(self): self.figure.clf() def hold_on(self): self.hold = True self.axes.hold(True) def hold_off(self): self.hold = False self.axes.hold(False) def set_dimensions(self, x1, y1, x2, y2): self.figure_canvas.SetDimensions(x1, y1, x2, y2) def show(self): self.figure_canvas.Show(True) def hide(self): self.figure_canvas.Show(False) def refresh(self): # Q&D refresh self.hide() self.show() def set_legend(self, legend): self.axes.set_title(legend, fontsize =20) def set_legend_01(self, legend = None): #ToDo: autoscale the figure windows to allow good view for the legend box ## self.axes.legend(legend) self.axes.legend(handlelen=0.05, loc=(1.06, 0.85), shadow=True) ## self.axes.autoscale_view def plot_data(self, real_values, imag_values , freq_values, title = "No data name"): if (len(real_values) != len(imag_values)): print "!! Error! Something is wrong with your data to plot" return if (len(real_values) != len(freq_values)): print "!! Error! Something is wrong with your data to plot" return # convert to numpy array data = array(real_values, dtype=complex) data.imag = imag_values if not self.hold: self.figure.clf() self.axes = self.figure.add_axes([0.1,0.1,0.8,0.8], projection='polar', aspect='equal') # plot smithchart circles # ----------------------- self.plotsmithcircles() # Plot the data #-------------- self.axes.plot(angle(data),abs(data),label=title,linewidth = 2,zorder=10) #self.axes.set_title( "Smith chart" , fontsize =20) # Show freq limits #----------------- self.axes.plot([angle(data[0])],[abs(data[0])],'oc',linewidth = 5,zorder=10) self.axes.plot([angle(data[len(data)-1])],[abs(data[len(data)-1])],'sm',linewidth = 5,zorder=10) # Disable Polar grid #------------------- self.axes.set_rgrids([1],['','']) self.axes.set_thetagrids([0,180],['','']) self.axes.grid(False) # Set the scale of smith chart #----------------------------- self.axes.set_rmax(1) def plotsmithcircles(self): linetype = 'k' linewidth = 0.5 linewidth2 = 1.5 # plot R circle r_array = (0.0, 0.2, 0.4, 0.7, 1.0, 1.4, 2.0, 3.0, 5.0) z = zeros((1,2000),complex) z.imag = arange(-50,50,0.05) x_shift = 1e-3 # can be 1e-3 but not zero for r in r_array: z.real = r gamma_r = transpose((z-1)/(z+1)) if r==1: self.axes.plot(angle(gamma_r), abs(gamma_r), linetype,linewidth = linewidth2,zorder=0) else: self.axes.plot(angle(gamma_r), abs(gamma_r), linetype,linewidth = linewidth,zorder=0) if not r==0: self.axes.text(angle((r+x_shift*1j-1)/(r+x_shift*1j+1)), 1e-6+abs((r+x_shift*1j-1)/(r+x_shift*1j+1)), "%.1f" %(r), backgroundcolor='white', alpha=1, horizontalalignment='center', verticalalignment='center', rotation=0) # plot X circle x_array = (0.2, 0.4, 0.6, 0.8, 1.0, 1.4, 2.0, 3.0, 5.0, 10.0) z = zeros((1,1000),complex) z.real = arange(0, 100, 0.1) for x in x_array: z.imag = x gamma_x = transpose((z-1)/(z+1)) if x==1: self.axes.plot(angle(gamma_x),abs(gamma_x), linetype,linewidth = linewidth2,zorder=0) else: self.axes.plot(angle(gamma_x),abs(gamma_x), linetype,linewidth = linewidth,zorder=0) self.axes.text(angle((x*1j-1)/(x*1j+1)),1.05,"%.1f" %(x),horizontalalignment='center',verticalalignment='center',rotation=angle((x*1j-1)/(x*1j+1),'Degrees')-90) for x in multiply(-1,x_array): z.imag = x gamma_x = transpose((z-1)/(z+1)) if x==-1: self.axes.plot(angle(gamma_x),abs(gamma_x), linetype,linewidth = linewidth2,zorder=0) else: self.axes.plot(angle(gamma_x),abs(gamma_x), linetype,linewidth = linewidth,zorder=0) self.axes.text(angle((x*1j-1)/(x*1j+1)),1.05,"%.1f" %(x),horizontalalignment='center',verticalalignment='center',rotation=angle((x*1j-1)/(x*1j+1),'Degrees')+90) # plot X=0 line self.axes.plot([-pi , 0],[1 , 1], linetype,linewidth = linewidth2 ,zorder=0) self.axes.text(-pi ,1.0,'0',horizontalalignment='center',verticalalignment='center',rotation = 0 , backgroundcolor='white',fontsize=12) # plot infinite symbol self.axes.text(0 ,1.0,'$\infty$',horizontalalignment='center',verticalalignment='center',rotation = 0 , backgroundcolor='white',fontsize=12) def plot_dummy(self): r1 = transpose(.1+arange ( 0 , 0.7 , 0.001)) theta1 = -1.5 * pi *r1 freq1 = r1*10e9 data1 = multiply(r1,exp(1j*theta1)) self.plot_data(data1.real, data1.imag,freq1,'my first data') self.hold_on() r2 = transpose(arange ( 0 , 0.9 , 0.001)) theta2 = +2 * pi *r2 freq2 = r2*10e9 data2 = multiply(r2,exp(1j*theta2)) ## self.plot_data(data2.real, data2.imag,freq2,'my second data') ## self.plot_data([0.4 ,0.2],[-0.5,0.5] ,[1,2],'my third data') self.set_legend("Test Smith Chart Plot") self.set_legend_01() ## r = transpose(.1+arange ( 0 , 0.7 , 0.001)) ## theta = -4.5 * pi *r ## freq = r*10e9 ## data = multiply(r,exp(1j*theta)) ## ## self.plot_data(data.real, data.imag,freq,'my first data') ## ## self.hold_on() ## ## ## r = transpose(arange ( 0 , 0.9 , 0.001)) ## theta = +2 * pi *r ## freq = r*10e9 ## data = multiply(r,exp(1j*theta)) ## ## self.plot_data(data.real, data.imag,freq,'my second data') ## ## self.set_legend() ############################################### if __name__ == '__main__': print "Testing PlotSmith Module..." app = wx.PySimpleApp() frame = wx.Frame(None, -1, "Testing PlotSmith Module", size = (800, 600)) frame.Show(True) PlotSmith = PlotSmith(frame) PlotSmith.plot_dummy() PlotSmith.show() app.MainLoop() app.Destroy() |
|
From: Michael D. <md...@st...> - 2009-03-19 12:01:00
|
Sherif Ahmed wrote: > > Hello all, > > I am using matplotlib in order to generate a scientific drawing called > “Smith Chart”. It consists of many shifted circles drawn in polar > plot. This chart is widely used in electrical engineering field. > > I am facing a problem now with the new version of matplotlib. After > trying around I figured out that the plot function does not connect > the given points in straight lines however by a circle or a circle > sector. This causes a very wrong drawing and producing parasitic, > false, circles when the points are to cross the theta=180° line. > You can turn off this feature by passing "resolution=1" to the polar() method. This is the default in SVN versions of matplotlib, and will be in the next releases. You've clearly done a lot of work on the Smith chart plotting already... It would be great to package that code into something for general use and include in the matplotlib core. Mike > > > ------------------------------------------------------------------------ > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------------ > Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are > powering Web 2.0 with engaging, cross-platform capabilities. Quickly and > easily build your RIAs with Flex Builder, the Eclipse(TM)based development > software that enables intelligent coding and step-through debugging. > Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com > ------------------------------------------------------------------------ > > _______________________________________________ > Matplotlib-devel mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-devel -- Michael Droettboom Science Software Branch Operations and Engineering Division Space Telescope Science Institute Operated by AURA for NASA |
|
From: Sherif A. <she...@lo...> - 2009-03-19 22:25:34
|
Hello Mike, Thanks for your advice. I think this is exactly what I need. I am not sure how to use this option, might you help me? I use simply the following lines in my code: self.figure.clf() self.axes = self.figure.add_axes([0.1,0.1,0.8,0.8], projection='polar', aspect='equal') and later: self.axes.plot(angle(data),abs(data),label=title,linewidth = 2,zorder=10) Where should I change the resolution feature? With each plot or with figure object? The code is currently open source and available via emGine software (http://www.petr-lorenz.com/emgine/index.php?option=com_content&view=article &id=46&Itemid=56) I am also willing to split smithchart plot as part of matplotlib, this would be great I think. Best regards, Sherif -----Original Message----- From: Michael Droettboom [mailto:md...@st...] Sent: Thursday, March 19, 2009 1:01 PM To: Sherif Ahmed Cc: mat...@li... Subject: Re: [matplotlib-devel] Polar Plot Sherif Ahmed wrote: > > Hello all, > > I am using matplotlib in order to generate a scientific drawing called > Smith Chart. It consists of many shifted circles drawn in polar > plot. This chart is widely used in electrical engineering field. > > I am facing a problem now with the new version of matplotlib. After > trying around I figured out that the plot function does not connect > the given points in straight lines however by a circle or a circle > sector. This causes a very wrong drawing and producing parasitic, > false, circles when the points are to cross the theta=180° line. > You can turn off this feature by passing "resolution=1" to the polar() method. This is the default in SVN versions of matplotlib, and will be in the next releases. You've clearly done a lot of work on the Smith chart plotting already... It would be great to package that code into something for general use and include in the matplotlib core. Mike > > > ------------------------------------------------------------------------ > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------ > > ---------------------------------------------------------------------------- -- > Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are > powering Web 2.0 with engaging, cross-platform capabilities. Quickly and > easily build your RIAs with Flex Builder, the Eclipse(TM)based development > software that enables intelligent coding and step-through debugging. > Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com > ------------------------------------------------------------------------ > > _______________________________________________ > Matplotlib-devel mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-devel -- Michael Droettboom Science Software Branch Operations and Engineering Division Space Telescope Science Institute Operated by AURA for NASA |
|
From: prosswa <rf...@tq...> - 2009-05-11 20:22:34
|
Hello, Does anyone know how I could plot contours on a chart like this? thanks, Robert -- View this message in context: http://www.nabble.com/Polar-Plot-tp22590831p23490797.html Sent from the matplotlib - devel mailing list archive at Nabble.com. |