コード例 #1
0
def curvelinear_test2(fig):
    """
    polar projection, but in a rectangular box.
    """

    # PolarAxes.PolarTransform takes radian. However, we want our coordinate
    # system in degree
    tr = Affine2D().scale(np.pi/180., 1.) + PolarAxes.PolarTransform()

    # polar projection, which involves cycle, and also has limits in
    # its coordinates, needs a special method to find the extremes
    # (min, max of the coordinate within the view).

    # 20, 20 : number of sampling points along x, y direction
    extreme_finder = angle_helper.ExtremeFinderCycle(50, 50,
                                                     lon_cycle = 360,
                                                     lat_cycle = None,
                                                     lon_minmax = None,
                                                     lat_minmax = (0, np.inf),
                                                     )

    grid_locator1 = angle_helper.LocatorDMS(12)
    # Find a grid values appropriate for the coordinate (degree,
    # minute, second).

    tick_formatter1 = angle_helper.FormatterDMS()
    # And also uses an appropriate formatter.  Note that,the
    # acceptable Locator and Formatter class is a bit different than
    # that of mpl's, and you cannot directly use mpl's Locator and
    # Formatter here (but may be possible in the future).

    grid_helper = GridHelperCurveLinear(tr,
                                        extreme_finder=extreme_finder,
                                        grid_locator1=grid_locator1,
                                        tick_formatter1=tick_formatter1
                                        )

    ax1 = SubplotHost(fig, 1, 1, 1, grid_helper=grid_helper)

    # make ticklabels of right and top axis visible.
    ax1.axis["right"].major_ticklabels.set_visible(True)
    ax1.axis["top"].major_ticklabels.set_visible(True)
    ax1.axis["left"].major_ticklabels.set_visible(True)

    # let right axis shows ticklabels for 1st coordinate (angle)
    ax1.axis["right"].get_helper().nth_coord_ticks=0
    # let bottom axis shows ticklabels for 2nd coordinate (radius)
    ax1.axis["bottom"].get_helper().nth_coord_ticks=0
    ax1.axis["left"].get_helper().nth_coord_ticks=0

    fig.add_subplot(ax1)


    ax1.quiver(0,0,50,50,angles='xy',scale_units='xy',scale=1)

    ax1.set_aspect(1.)
    ax1.set_xlim(-100, 100)
    ax1.set_ylim(-100, 100)

    ax1.grid(True)
コード例 #2
0
class PolarPlot:
	''' plots heading angle and signal strength in polar coor in 2d'''
	def __init__(self):
		plt.ion()
		self.fig = plt.figure(num=2, figsize=(10,7))
		tr = Affine2D().scale(np.pi/180., 1.) + PolarAxes.PolarTransform()
		# 20, 20 : number of sampling points along x, y direction
		extreme_finder = angle_helper.ExtremeFinderCycle(50, 50,
		                                                 lon_cycle = 360,
		                                                 lat_cycle = None,
		                                                 lon_minmax = None,
		                                                 lat_minmax = (0, np.inf),
		                                                 )
		grid_locator1 = angle_helper.LocatorDMS(15)
		tick_formatter1 = angle_helper.FormatterDMS()
		# And also uses an appropriate formatter.  Note that,the
		# acceptable Locator and Formatter class is a bit different than
		# that of mpl's, and you cannot directly use mpl's Locator and
		# Formatter here (but may be possible in the future).
		grid_helper = GridHelperCurveLinear(tr,
		                                    extreme_finder=extreme_finder,
		                                    grid_locator1=grid_locator1,
		                                    tick_formatter1=tick_formatter1
		                                    )

		self.ax1 = SubplotHost(self.fig, 1, 1, 1, grid_helper=grid_helper)
		
		# make ticklabels of right and top axis visible.
		self.ax1.axis["right"].major_ticklabels.set_visible(True)
		self.ax1.axis["top"].major_ticklabels.set_visible(True)
		self.ax1.axis["left"].major_ticklabels.set_visible(True)

		# let right axis shows ticklabels for 1st coordinate (angle)
		self.ax1.axis["right"].get_helper().nth_coord_ticks=0
		# let bottom axis shows ticklabels for 1st coordinate (angle)
		self.ax1.axis["bottom"].get_helper().nth_coord_ticks=0
		self.ax1.axis["left"].get_helper().nth_coord_ticks=0
		temp =  self.ax1.set_title('Signal strength & heading polar plots')
		temp.set_y(1.05) 

		self.ax1.grid(True)

		# insert x and y axises
		self.ax = self.fig.add_subplot(self.ax1)
		self.ax1.spines['left'].set_position('center')
		self.ax1.spines['right'].set_color('red')
		self.ax1.spines['bottom'].set_position('center')
		self.ax1.spines['top'].set_color('none')
		self.ax1.spines['left'].set_smart_bounds(True)
		self.ax1.spines['bottom'].set_smart_bounds(True)
		self.ax1.xaxis.set_ticks_position('bottom')
		self.ax1.yaxis.set_ticks_position('left')
		self.ax1.axhline(linewidth=2, color='blue')
		self.ax1.axvline(linewidth=2, color='blue')

		# label x and y axises manually 
		ticks = np.linspace(0, 255, 6)
		offset = np.zeros([1,255])
		for i in range(1,5):
			self.ax1.annotate(str(ticks[i]),size=10, xy=(ticks[i], -15))
			blah = self.ax1.plot(ticks[i],0, 'bo')

			self.ax1.annotate(str(ticks[i]),size=10, xy=(5, ticks[i]))
			blah = self.ax1.plot(0,ticks[i], 'bo')

		# annotate figure 
		bbox_props = dict(boxstyle="round", fc="w", ec="0.5", alpha=0.9)
		# self.annotation = self.ax1.annotate('init',size=20, xy=(100, 100), bbox = bbox_props)
		self.annotation = plt.figtext(0.02, 0.9, 'rssi = ', size=20, alpha = 0.9, bbox = bbox_props)
		self.Freq = plt.figtext(0.85, 0.85, 'freq = ???', size=10, alpha = 0.9, bbox = bbox_props)
		self.Freq = plt.figtext(0.85, 0.9, 'Horizontal Plane', size=10, alpha = 0.9, bbox = bbox_props)

		# initialize arrow 
		self.quiverLine = self.ax1.quiver(0,0,50,50,angles='xy',scale_units='xy',scale=1)		
		self.ax1.set_aspect(1.)
		self.ax1.set_xlim(-255, 255)
		self.ax1.set_ylim(-255, 255)
		
		# initialize mesh plot
		self.xdata = []
		self.ydata = []
		self.polarline, = self.ax1.plot(self.xdata,self.ydata)

	def update(self, signalStrength, yaw):
		U = signalStrength*cos(yaw*pi/180)
		V = signalStrength*sin(yaw*pi/180)
		self.xdata.append(U)
		self.ydata.append(V)
		self.polarline.set_data(self.xdata,self.ydata)
		self.quiverLine.set_UVC(U,V)
		self.annotation.set_text('rssi = ' + str(signalStrength))
		plt.draw()