## matplotlib-users

 [Matplotlib-users] Polar plot From: jan gillis - 2008-09-16 23:00:59 Hello, I have a problem with polar plot, if i run the following code in matplotlib 0.98.3, polar plot is drawing a extra circle to go from angle -3.14159265 to angle 3.03753126. Is there a solution for this problem? ******************** import numpy as np from matplotlib.pyplot import figure, show, rc, grid # radar green, solid grid lines rc('grid', color='#316931', linewidth=1, linestyle='-') rc('xtick', labelsize=15) rc('ytick', labelsize=15) # force square figure and square axes looks better for polar, IMO fig = figure(figsize=(8,8)) ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True, axisbg='#d5de9c') z = np.zeros((1,2000),complex) z.real = 0.2 z.imag = np.arange(-50,50,0.05) gamma_r = np.transpose((z-1)/(z+1)) ax.plot(np.angle(gamma_r), np.abs(gamma_r), '.-', zorder=0) ax.set_rmax(2.0) grid(True) show() ******************** Kind regards, Jean -- Jan Gillis Ghent University IMEC vzw - INTEC Sint-Pietersnieuwstraat 41 B-9000 Gent Belgium tel. +32 9 264 33 33 jan.gillis@...
 Re: [Matplotlib-users] Polar plot From: Tony S Yu - 2008-09-17 09:26:13 On Sep 17, 2008, at 1:59 AM, jan gillis wrote: > Hello, > > I have a problem with polar plot, if i run the following code in > matplotlib 0.98.3, polar plot is drawing a extra circle to go from > angle -3.14159265 to angle 3.03753126. Is there a solution for this > problem? > > ******************** > import numpy as np > from matplotlib.pyplot import figure, show, rc, grid > > # radar green, solid grid lines > rc('grid', color='#316931', linewidth=1, linestyle='-') > rc('xtick', labelsize=15) > rc('ytick', labelsize=15) > > # force square figure and square axes looks better for polar, IMO > fig = figure(figsize=(8,8)) > ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True, axisbg='#d5de9c') > > z = np.zeros((1,2000),complex) > z.real = 0.2 > z.imag = np.arange(-50,50,0.05) > gamma_r = np.transpose((z-1)/(z+1)) > > ax.plot(np.angle(gamma_r), np.abs(gamma_r), '.-', zorder=0) Hi Jan, It looks like you get the circle because the angles you're plotting go from negative to positive radians in a weird way. The circle being drawn starts around 0 radians and goes clockwise by negative values. Then when it gets to - pi, it switches to positive indices, i.e. pi. Of course, these are the same points on a polar plot, but different angles, if you want to be consistent. Here are a couple of quick solutions, but there but there maybe better ways of handling this. # ~~~~~~~~~~~~~~~~~~ # get rid of the plot line above, and add the following theta = np.angle(gamma_r) mag = np.abs(gamma_r) # option 1 ordered = np.argsort(theta, axis=0).squeeze() ax.plot(theta[ordered], mag[ordered], '.-', zorder=0) # option 2 neg_theta = np.where(theta < 0) theta[neg_theta] += 2 * np.pi ax.plot(theta, mag, '.-', zorder=0) # ~~~~~~~~~~~~~~~~~~ I hope that's helpful, -Tony > > ax.set_rmax(2.0) > grid(True) > > show() > > ******************** > Kind regards, > Jean > > -- > Jan Gillis > Ghent University > IMEC vzw - INTEC > Sint-Pietersnieuwstraat 41 > B-9000 Gent > Belgium > tel. +32 9 264 33 33 > jan.gillis@... > > > ------------------------------------------------------------------------- > This SF.Net email is sponsored by the Moblin Your Move Developer's > challenge > Build the coolest Linux based applications with Moblin SDK & win > great prizes > Grand prize is a trip for two to an Open Source event anywhere in > the world > http://moblin-contest.org/redirect.php?banner_id=100&url=/ > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users