本文整理汇总了Python中matplotlib.pyplot.polar函数的典型用法代码示例。如果您正苦于以下问题:Python polar函数的具体用法?Python polar怎么用?Python polar使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了polar函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main():
re = []
rm = []
t = []
ve = []
vm = []
earth = Planet()
earth.set_e(0.0167)
earth.set_rmin(1.471E11)
earth.set_period(365*86400)
earth.set_semi_major_axis(149600000)
mars = Planet()
mars.set_e(0.09341233)
mars.set_rmin(2.0662E11)
mars.set_period(687*86400)
mars.set_semi_major_axis(227920000)
for x in range(0, int(sys.argv[1])):
re.append(earth.step())
rm.append(mars.step())
ve.append(earth.velocity())
vm.append(mars.velocity())
t.append(earth.theta)
sys.stdout.write("\rStep " + str(earth.count) + " / " + sys.argv[1] + " " + str((float(earth.count)/float(sys.argv[1]))*100) + "% " + str(earth.theta) + " " + str(mars.theta))
sys.stdout.flush()
print "\n"
plt.figure(1)
plt.polar(t, re)
plt.polar(t, rm)
plt.figure(2)
plt.plot(t, ve)
plt.plot(t, vm)
plt.show()
示例2: plot_phaseplot_lpf
def plot_phaseplot_lpf(dictdata, keys, autok, title, withn='yes'):
colors = ['r', 'b', 'g', 'y', 'k']
plt.suptitle(title, fontsize='large' )
if autok == 'yes':
k = dictdata.keys()
for i, condition in enumerate(keys):
datac = colors[i]
data = dictdata[condition]
try:
n = len(data)
theta, r = zip(*data)
except TypeError:
theta, r = data
n = 1
if withn == 'yes':
plt.polar(theta, r, 'o', color=datac, label=condition + '\n n=' + str(n))
if withn == 'no':
plt.polar(theta, r, 'o', color=datac, label=condition)
#lines, labels = plt.rgrids( (1.0, 1.4), ('', ''), angle=0 )
tlines, tlabels = plt.thetagrids( (0, 90, 180, 270), ('0', 'pi/2', 'pi', '3pi/2') )
leg = plt.legend(loc=(0.95,0.75))
for t in leg.get_texts():
t.set_fontsize('small')
plt.subplots_adjust(top=0.85)
plt.draw()
示例3: plot_SParameters
def plot_SParameters(self, S='S21' , style='MA'):
'''plot S parameter from data
Input:
- S (String) ["S11", "S12", "S21", "S22"]: Set which parameter you want to plot
- asked_format ("String") ["MA", "DB", "RI"]: Set in which format we would like to have plot
Output:
- matplotlib 2d figure
'''
x, y, z = self.get_SParameters(S, style)
factor = self.get_frequency_unit(style='Float')
if factor == 1. :
x_label = 'Frequency [Hz]'
elif factor == 1e3 :
x_label = 'Frequency [kHz]'
elif factor == 1e6 :
x_label = 'Frequency [MHz]'
elif factor == 1e9 :
x_label = 'Frequency [GHz]'
fig = plt.figure()
if re.match('^[mM][aA]$', style) :
ax1 = fig.add_subplot(211)
ax1.plot(x, y, label=S)
plt.ylabel('Amplitude [V]')
plt.grid()
elif re.match('^[dD][bB]$', style) :
ax1 = fig.add_subplot(211)
ax1.plot(x, y, label=S)
plt.ylabel('Attenuation [dB]')
plt.grid()
if re.match('^[dD][bB]$|^[mM][aA]$', style):
ax2 = fig.add_subplot(212, sharex = ax1)
ax2.plot(x, z, label=S)
plt.ylabel('Phase [deg]')
plt.xlabel(x_label)
elif re.match('^[rR][iI]$', style):
ax1 = fig.add_subplot(111)
y = y*1./y.max()
plt.polar(y, z, label=S)
plt.title('Normalised amplitude')
plt.ylabel('Real part')
plt.ylabel('Imaginary part')
plt.legend(loc='best')
plt.grid()
plt.show()
示例4: test_polar_units
def test_polar_units():
import matplotlib.testing.jpl_units as units
from nose.tools import assert_true
units.register()
pi = np.pi
deg = units.UnitDbl( 1.0, "deg" )
km = units.UnitDbl( 1.0, "km" )
x1 = [ pi/6.0, pi/4.0, pi/3.0, pi/2.0 ]
x2 = [ 30.0*deg, 45.0*deg, 60.0*deg, 90.0*deg ]
y1 = [ 1.0, 2.0, 3.0, 4.0]
y2 = [ 4.0, 3.0, 2.0, 1.0 ]
fig = plt.figure()
plt.polar( x2, y1, color = "blue" )
# polar( x2, y1, color = "red", xunits="rad" )
# polar( x2, y2, color = "green" )
fig = plt.figure()
# make sure runits and theta units work
y1 = [ y*km for y in y1 ]
plt.polar( x2, y1, color = "blue", thetaunits="rad", runits="km" )
assert_true( isinstance(plt.gca().get_xaxis().get_major_formatter(), units.UnitDblFormatter) )
示例5: drawPair
def drawPair(self, pair, label):
start_angle = self.hourToAngle(pair[1])
end_angle = self.hourToNextAngle(pair[0], start_angle)
new_angles = np.linspace(start_angle, end_angle, 20)
new_points = np.ones(len(new_angles))
plt.polar(new_angles, new_points)
plt.fill_between(new_angles, new_points, facecolor='yellow', alpha=0.5)
self.drawLabel(new_angles, new_points, label)
示例6: floret_revolutions
def floret_revolutions(n, **kwargs):
r = np.arange(n)
F = fibonacci_lim(r[-1])
plt.figure(figsize=(6,6))
plt.polar(np.mod(r/phi,1)*2*np.pi, r, '.', **kwargs)
plt.polar(np.mod(F/phi,1)*2*np.pi, F, 'r.', **kwargs)
plt.gca().set_rticks([])
plt.show()
示例7: display_picture
def display_picture(points):
"""Graphs the points given on a polar coordinate grid"""
r_vals = []
theta_vals = []
for r, theta in points:
r_vals.append(r)
theta_vals.append(theta)
pyplot.polar(r_vals, theta_vals, linestyle='solid', marker='o')
pyplot.show()
示例8: plot_orbit
def plot_orbit(self):
ta = self.trueAnom()
sma = self.smAxis()[0]
e = self.ecc()
theta = np.linspace(0,2*math.pi,360)
r=(sma*(1-e**2))/(1+e*np.cos(theta))
plt.polar(theta, r)
print(np.c_[r,theta])
plt.savefig("Orbit.png")
plt.show()
示例9: my
def my(heart):
r, t = heart
plt.polar(r, t, 'r', lw=5)
tick_params = {'axis':'y', 'which':'both',
'bottom': False, 'top':False,
'left': False, 'right': False,
'labelbottom': False, 'labelleft': False}
plt.tick_params(**tick_params)
plt.show()
示例10: plot_diff_cross_sect
def plot_diff_cross_sect(self, **kwargs):
"""Displays a plot of the differential cross section.
Arguments:
**kwargs: Any additional arguments to plot
Returns:
Displays the plot
"""
tgrid = np.linspace(-np.pi,np.pi,361)
plt.polar(tgrid,self.diff_cross_sect(tgrid), marker='.', **kwargs)
plt.show()
示例11: show_floret_growth
def show_floret_growth(theta, r, prefix='frame', grow=True, ms=10):
n = len(r)
savefmt = prefix + '%0' + str(len(str(n-1))) + 'i.png'
plt.figure(figsize=(6,6))
for i in range(n):
plt.clf()
if grow: s = float(n - i - 1) / n
else: s = 0.
plt.polar(theta[:i+1], r[:i+1]-s, '.', mec='k', mfc='b', ms=ms)
plt.polar(theta[i], r[i]-s, '.', mec='k', mfc='r', ms=ms)
plt.gca().set_rlim([0, 1])
plt.gca().set_rticks([])
plt.savefig(savefmt %i)
示例12: main
def main():
earth = Body([0, 147090000000], 2929000, 5.9726E24, Orbit(0.016710219, 149600000000, 1.495583757E8, 365))
# print earth.orbit.radius_from_angle(math.pi)
# print earth.orbit.find_e_anomaly(271433.6, 0.016710219)
# print earth.orbit.find_true_anomaly(earth.orbit.find_e_anomaly(271433.6, 0.016710219))
theta = []
radius = []
for time in [3]:
earth.orbit.calc_position(time)
theta.append(earth.orbit.true_anomaly)
radius.append(earth.orbit.radius)
plt.polar(theta, radius, 'o')
plt.show()
示例13: polar_demo
def polar_demo():
"""Make a polar plot of some random angles.
"""
# Sample a bunch of random angles
A = rand.randint(0, 360, 100)
# Plot each angle as a point with radius 1
plt.figure()
plt.polar(A, np.ones_like(A), 'ko')
# Disable y-ticks, because they are distracting
plt.yticks([], [])
plt.title("Polar Demo", fontsize=titlesize)
示例14: plot_phase
def plot_phase(control=None, state0=None):
"""generates a phase portrait and phase trajectory from initial conditions"""
#time = np.linspace(0, 20, 100) not needed for simulate()
results, time = simulate(100, 10, control, state0)
theta, h = results[:,0], results[:,1]
state0 = (theta[0], h[0])
#statew = [theta[-1], h[-1]]
#print "Final: ", statew
#system trajectory
plot.figure(1)
plot.plot(theta, h, color='green') #use polar(theta, h)?
plot.figure(2)
plot.polar(theta, h, color='green')
#phase portrait (vector field)
thetamax, hmax = max(abs(theta)), max(abs(h))
theta, h = numpy.meshgrid(numpy.linspace(-thetamax, thetamax, 10),
numpy.linspace(-hmax, hmax, 10))
Dtheta, Dh = numpy.array(theta), numpy.array(h)
for i in range(theta.shape[0]):
for j in range(theta.shape[1]):
Dtheta[i,j] = dtheta(float(theta[i,j]), float(h[i,j]))
Dh[i,j] = dh(float(theta[i,j]), float(h[i,j]))
plot.figure(1)
plot.quiver(theta, h, Dtheta, Dh) #no polar equivalent...
#optimal path mode
h = numpy.linspace(-hmax, hmax, 100)
plot.plot(path(h), h, color='blue') #use polar(theta, h)?
if control is None:
plot.savefig("optimal-satellite-cart.png", dpi=200)
else:
plot.savefig("satellite-nonoptimal-cart.png", dpi=200)
plot.xlabel("angle (rad)")
plot.ylabel("angular momentum (N-m-s)")
#optimal mode in polar
plot.figure(2)
plot.polar(path(h), h, color='blue')
if control is None:
plot.savefig("optimal-satellite-polar.png", dpi=200)
else:
plot.savefig("satellite-nonoptimal-polar.png", dpi=200)
plot.xlabel("angle (rad)")
plot.ylabel("angular momentum (N-m-s)")
plot.plot(state0[0], state0[1], 'o', color='green')
plot.show()
示例15: relative_direction_distribution
def relative_direction_distribution(xy,verbose=False):
"""computes instantaneous directions and make an histogram centered on previous direction
"""
dxy = xy[1:,:]-xy[0:-1,:]
theta = npy.arctan2(dxy[:,0],dxy[:,1])
rho = npy.sqrt(npy.sum(dxy**2,axis=1))
dtheta = theta[1:]-theta[0:-1]
dtheta = npy.hstack(([0],dtheta))
#verify that theta is in [-pi,+pi]
clip_dtheta = dtheta.copy()
clip_dtheta[dtheta>npy.pi] = dtheta[dtheta>npy.pi] - 2.*npy.pi
clip_dtheta[dtheta<-npy.pi] = dtheta[dtheta<-npy.pi] + 2.* npy.pi
#resulting direction and dispersion
(R,V,Theta,Rtot) = rayleigh(rho,clip_dtheta)
#distribution
N = 8
width = 2*npy.pi/N
offset_th = .5*width
bins = npy.linspace(-npy.pi-offset_th,npy.pi+offset_th,N+2,endpoint=True)
h_theta,bin_theta = npy.histogram(clip_dtheta,bins=bins,weights=rho) # ! weighted histogram
#grouping first and last bin corresponding to the same direction
h_theta[0]+=h_theta[-1]
if verbose:
import matplotlib.pyplot as plt
fig=plt.figure()
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True,)
# #plot polar histogram bins
# ax.bar(bin_theta[0:-1], npy.ones_like(bin_theta[0:-1]), width=width, bottom=0.0,alpha=.5)
#plot polar distribution
ax.bar(bin_theta[0:-2], h_theta[:-1], width=width, bottom=0.0,label='rel.direction hist.')
#plot relative displacement
plt.polar(clip_dtheta,rho, 'yo',label='rel.direction')
#plot main direction and dispersion
plt.polar(Theta,R*Rtot,'ro',label='avg.')
ax.bar(Theta-V/2, R*Rtot*.01, color='k',width=V, bottom=R*Rtot,label='dispersion')
ax.legend(loc='upper left')
#plot xy trajectory
ax = fig.add_axes([0.1, 0.1, 0.2, 0.2])
plt.plot(xy[:,0],xy[:,1])
plt.plot(xy[0,0],xy[0,1],'k+')
plt.show()
return (R,V,Theta,Rtot,clip_dtheta,rho)