Hi Eric,
Thanks agaon. Now it works after updating to matplotlib 98.5.
Well I also attach the code. I find it good if we can publish it to other
interested users. May be some one needs it or likes to upgrade it. I made
already the basic work. How does this work? Should I distribute it via the
list here or somewhere else?
I am not expert in this stuff :)
Nice wishes,
Sherif
-----Original Message-----
From: Eric Firing [mailto:efir...@hawaii.edu]
Sent: Saturday, March 21, 2009 7:13 PM
To: Sherif Ahmed
Cc: 'Michael Droettboom'; matplotlib-devel@lists.sourceforge.net
Subject: Re: [matplotlib-devel] Polar Plot
Sherif Ahmed wrote:
> Hello Eric,
>
> I am afraid this does not work. I get error saying that :
> AttributeError: 'PolarAxes' object has no attribute 'set_resolution'
It looks like support for the resolution kwarg was added late in
January, so you need either a more recent version, or an older version.
Unfortunately, it also looks like the latest release was before this
change.
Maybe it is time for another release, either 0.98.5 maintenance or
trunk. Or both. Releases are not my area, though.
Eric
>
> The full error text is:
> -----------------------------------------
> Traceback (most recent call last):
> File "D:\EmGine
>
Project\emGine_GUI_0_7_5__11022009\emGine_GUI_0_7_5\emGineGUI\PlotSmith.py",
> line 287, in <module>
> PlotSmith.plot_dummy()
> File "D:\EmGine
>
Project\emGine_GUI_0_7_5__11022009\emGine_GUI_0_7_5\emGineGUI\PlotSmith.py",
> line 241, in plot_dummy
> self.plot_data(data1.real, data1.imag,freq1,'my first data')
> File "D:\EmGine
>
Project\emGine_GUI_0_7_5__11022009\emGine_GUI_0_7_5\emGineGUI\PlotSmith.py",
> line 144, in plot_data
> self.axes = self.figure.add_axes([0.1,0.1,0.8,0.8],
projection='polar',
> resolution = 1, aspect='equal')
> File
>
"c:\python25\lib\site-packages\matplotlib-0.98.3.0001-py2.5-win32.egg\matplo
> tlib\figure.py", line 615, in add_axes
> a = projection_factory(projection, self, rect, **kwargs)
> File
>
"c:\python25\lib\site-packages\matplotlib-0.98.3.0001-py2.5-win32.egg\matplo
> tlib\projections\__init__.py", line 44, in projection_factory
> return get_projection_class(projection)(figure, rect, **kwargs)
> File
>
"c:\python25\lib\site-packages\matplotlib-0.98.3.0001-py2.5-win32.egg\matplo
> tlib\projections\polar.py", line 171, in __init__
> Axes.__init__(self, *args, **kwargs)
> File
>
"c:\python25\lib\site-packages\matplotlib-0.98.3.0001-py2.5-win32.egg\matplo
> tlib\axes.py", line 537, in __init__
> if len(kwargs): martist.setp(self, **kwargs)
> File
>
"c:\python25\lib\site-packages\matplotlib-0.98.3.0001-py2.5-win32.egg\matplo
> tlib\artist.py", line 894, in setp
> func = getattr(o,funcName)
> AttributeError: 'PolarAxes' object has no attribute 'set_resolution'
>
>
> -----------------------------------------
>
> Do you know what is the reason behind this?
>
> Thanks,
> Sherif
>
> -----Original Message-----
> From: Eric Firing [mailto:efir...@hawaii.edu]
> Sent: Thursday, March 19, 2009 11:39 PM
> To: Sherif Ahmed
> Cc: 'Michael Droettboom'; matplotlib-devel@lists.sourceforge.net
> Subject: Re: [matplotlib-devel] Polar Plot
>
> Sherif Ahmed wrote:
>> 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',
> resolution=1,
>> 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?
>
> Put the resolution kwarg in the call to the add_axes method. The way
> the line is drawn between points--whether as a straight line on the plot
> or by interpolating in the data coordinates--is controlled on a per-axes
> basis by this kwarg when the axes are created.
>
> Eric
>
#######################################################################
#
# $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.4 2009/03/21 Sherif
# Adding kwrg resolution = 1 in add_axes call
# to switch off the automatic smoothing option
# of matplotlib library, valid up to matplotlib
# 98.5. Older version should not be used
#
# 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',
resolution = 1, 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()
------------------------------------------------------------------------------
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
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel