Example #1
0
def scatter_classic(x, y, s=None, c='b'):
    """
    SCATTER_CLASSIC(x, y, s=None, c='b')

    Make a scatter plot of x versus y.  s is a size (in data coords) and
    can be either a scalar or an array of the same length as x or y.  c is
    a color and can be a single color format string or an length(x) array
    of intensities which will be mapped by the colormap jet.

    If size is None a default size will be used

    Copied from older version of matplotlib -- removed in version 0.9.1
    for whatever reason.
    """
    self = gca()
    if not self._hold: self.cla()
    if is_string_like(c):
        c = [c] * len(x)
    elif not iterable(c):
        c = [c] * len(x)
    else:
        norm = normalize()
        norm(c)
        c = cm.jet(c)

    if s is None:
        s = [abs(0.015 * (amax(y) - amin(y)))] * len(x)
    elif not iterable(s):
        s = [s] * len(x)

    if len(c) != len(x):
        raise ValueError, 'c and x are not equal lengths'
    if len(s) != len(x):
        raise ValueError, 's and x are not equal lengths'

    patches = []
    for thisX, thisY, thisS, thisC in zip(x, y, s, c):
        circ = Circle(
            (thisX, thisY),
            radius=thisS,
        )
        circ.set_facecolor(thisC)
        self.add_patch(circ)
        patches.append(circ)
    self.autoscale_view()
    return patches
Example #2
0
def scatter_classic(x, y, s=None, c='b'):
    """
    SCATTER_CLASSIC(x, y, s=None, c='b')

    Make a scatter plot of x versus y.  s is a size (in data coords) and
    can be either a scalar or an array of the same length as x or y.  c is
    a color and can be a single color format string or an length(x) array
    of intensities which will be mapped by the colormap jet.

    If size is None a default size will be used

    Copied from older version of matplotlib -- removed in version 0.9.1
    for whatever reason.
    """
    self = gca()
    if not self._hold: self.cla()
    if is_string_like(c):
        c = [c]*len(x)
    elif not iterable(c):
        c = [c]*len(x)
    else:
        norm = normalize()
        norm(c)
        c = cm.jet(c)

    if s is None:
        s = [abs(0.015*(amax(y)-amin(y)))]*len(x)
    elif not iterable(s):
        s = [s]*len(x)

    if len(c)!=len(x):
        raise ValueError, 'c and x are not equal lengths'
    if len(s)!=len(x):
        raise ValueError, 's and x are not equal lengths'

    patches = []
    for thisX, thisY, thisS, thisC in zip(x,y,s,c):
        circ = Circle( (thisX, thisY),
                       radius=thisS,
                       )
        circ.set_facecolor(thisC)
        self.add_patch(circ)
        patches.append(circ)
    self.autoscale_view()
    return patches
Example #3
0
 def setupDummyArm(self):
     if self.anim:
         ion()
         self.fig = figure() # create figure
         l = 1.1*sum(self.armLen)
         self.ax = self.fig.add_subplot(111, autoscale_on=False, xlim=(-l/2, +l), ylim=(-l/2, +l)) # create subplot
         self.ax.grid()
         self.line, = self.ax.plot([], [], 'o-', lw=2)
         self.circle = Circle((0,0),0.04, color='g', fill=False)
         self.ax.add_artist(self.circle)
def plot_targets(ax=None, targets=None, facecolor='none', radius=2, **kwargs):
    if ax == None:
        plt.figure()
        ax = plt.subplot(111)

    from pylab import Circle

    patches = []
    for target in targets:
        c = Circle(target[[0,2]], radius=radius, facecolor=facecolor, **kwargs)
        patches.append(c)
        ax.add_patch(c)
Example #5
0
 def plotTraj(self):
     fig = figure() 
     l = 1.1*sum(self.armLen)
     ax = fig.add_subplot(111, autoscale_on=False, xlim=(-l/2, +l), ylim=(-l/2, +l)) # create subplot
     posX, posY = zip(*[self.angles2pos([x[SH],x[EL]], self.armLen) for x in self.angAll])
     ax.plot(posX, posY, 'r')
     targ = Circle((self.targetPos),0.04, color='g', fill=False) # target
     ax.add_artist(targ)
     ax.grid()
     ax.set_title('X-Y Hand trajectory')
     xlabel('x')
     ylabel('y')
Example #6
0
    def add_to_polar(self, ax, draw_bearing_change=False):
        """
        Draw the beetle's path onto the 2D polar axes.
        :param ax: 2D axes for display.
        :param draw_bearing_change: Boolean, set to tru if you want to draw the beetle's second roll.
        :return: Unused
        """
        o_x = 0
        o_y = 0

        # Plot the beetle start point
        ax.plot(o_x,
                o_y,
                color=colours.BEETLE_COLOUR,
                marker='o',
                markersize=5)

        # Plot the first roll
        roll_vector = self.__first_roll.get_polar_as_list()
        cue_vector = self.__first_cue.get_polar_as_list()

        if draw_bearing_change:
            # Plot the second roll
            roll_vector = self.__second_roll.get_polar_as_list()
            cue_vector = self.__second_cue.get_polar_as_list()

        print("Roll Vector length: " + str(len(roll_vector)))
        print("Cue Vector length: " + str(len(cue_vector)))

        # Quiver plot
        ax.quiver([o_x, o_x], [o_y, o_y], [roll_vector[0], cue_vector[0]],
                  [roll_vector[1], cue_vector[1]],
                  color=[colours.BEETLE_ROLL_COLOUR, colours.CUE_COLOUR],
                  angles='xy',
                  scale_units='xy',
                  scale=1)

        # If a confidence threshold has been set, draw it on the polar plot
        if self.__confidence_threshold > 0:

            confidence_ring = Circle(
                (0, 0),
                self.__confidence_threshold,
                alpha=0.3,
                color=colours.CONFIDENCE_THRESHOLD_COLOUR,
                transform=ax.transData.
                _b  # Required to get the circle to plot correctly in polar axes.
            )
            ax.add_artist(confidence_ring)
    def plot_targets(self, ax=None, targets=None, facecolor='none', **kwargs):
        if ax == None:
            plt.figure()
            ax = plt.subplot(111)

        if targets == None:
            targets = self.get_targets()

        from pylab import Circle
        target_radius = self.target_radius

        patches = []
        for target in targets:
            c = Circle(target[[0,2]], radius=target_radius, facecolor=facecolor, **kwargs)
            patches.append(c)
            ax.add_patch(c)

        return ax, patches
Example #8
0
z = np.array([[0.0, 3.0], [3.0, 2.0]], dtype='d')
lambdaK = 0.8
minHDist = 0.01
hv = 0.2  # for velocity field grid
y_crcl = 1.5
thet = np.linspace(2 * np.pi, 0, n + 1, endpoint=True)

x = np.array([np.cos(thet), y_crcl + np.sin(thet)])
A, f = ieFredgolm2dk(x, x, lambdaK, 0.0, q, z, varphiSources, Py, Phi1)
g = np.linalg.solve(A, f)
xs = np.mgrid[-4.:4.0001:hv, 0.0001:4.0001:hv]
xs = xs[:, ((xs[0] - z[0][0])**2 + (xs[1] - z[1][0])**2) > 0.4]
xs = xs[:, ((xs[0] - z[0][1])**2 + (xs[1] - z[1][1])**2) > 0.4]
Ws = VSources(q, xs, z, Kx, Phi1) + VDL(xs, x, g, Hx, Psi2)
from pylab import quiver, show, gca, Circle, text, axis, grid
gca().add_patch(Circle((0, y_crcl), radius=1, alpha=.5, fc='y'))
quiver(xs[0], xs[1], Ws[0], Ws[1], color='r')
"""
# Testing on the exact solution
qOut=np.array([np.pi,lambdaK*np.pi,-lambdaK*np.pi])
zOut=np.array([[0.0,0.0,0.0],[2.0,0.5,0.0]],dtype='d')
xOut=xs[:,(xs[0]**2+xs[1]**2)>(1+minHDist)**2]
WOut=VSources(qOut,xOut,zOut)
WNOut=VSources(q,xOut,z)+VDL(xOut,x,g)
etaOut=(1.-np.sqrt(WNOut[0]**2+WNOut[1]**2)/np.sqrt(WOut[0]**2+WOut[1]**2))*100
etaOutMax=np.max(etaOut)
print etaOut
text(-2.5,3.1,ur"$\eta_{Out,max}=%6.4f$per." % etaOutMax)

qIn=np.array([(1-lambdaK)*np.pi])
xIn=xs[:,(xs[0]**2+xs[1]**2)<(1-minHDist)**2]
Example #9
0
def plot_mediatrix_circle(mediatrix_data,ps_name, keydots=False, colors= {'object': "g", 'vector': "b", 'keydots': "k"}, mediatrix_vectors=False, save=True, plot_title="Mediatrix Plot", out_image=""):
    """
    Make a plot presenting the object, keydots and mediatrix vectors. 

    Input:
    - mediatrix_data <list> : the output from mediatrix_decomposition.
    - image_dir   <str> : the image directory. If it is on the same directory directory=''.
    - keydots   <bool> : 'True' if you want to display the keydots and 'False' if you do not. 
    - colors   <dic> : set the plot colors. The possible keys are 'object', 'vector' and 'keydots'.       
    Output:
     <bool>
         
    """
    if out_image=='':
        out_image=ps_name.replace(".fits","")+"_mediatrix_circle.png"
  
    image,hdr = getdata(ps_name, header = True )
    pixels=where(image>0)    
    A = subplot(111)
    for i in range (0,len(pixels[0])):
        xy=[pixels[1][i]-0.5,pixels[0][i]-0.5]
        rec=Rectangle(xy, 1, 1, ec=colors['object'], fc=colors['object'], zorder=100)
        A.add_patch(rec)
    #A.scatter(pixels[1], pixels[0], s=200, c='b', marker='s', edgecolors='none')
    #A.plot(pixels[1],pixels[0],colors['object'])
    Length=0
    for i in range(0,len(mediatrix_data['origin'])):
        origin_x=mediatrix_data['origin'][i].real
        origin_y=mediatrix_data['origin'][i].imag
        end_x=mediatrix_data['end'][i].real
        end_y=mediatrix_data['end'][i].imag
        Length_aux=(origin_x - end_x)**2 + (origin_y - end_y)**2
        Length=Length+ sqrt(Length_aux)
        if mediatrix_vectors==True:
            d_x= end_x - origin_x
            d_y= mediatrix_data['end'][i].imag - mediatrix_data['origin'][i].imag
            arr = Arrow(origin_y, origin_x, d_y, d_x, width=0.05*Length, fc=colors['vector'], ec='none',zorder=1000)
            A.add_patch(arr)
      
    if keydots==True:
        E1,E2=get_extrema_2loops(pixels[0], pixels[1], 0 )
        Area=len(pixels[1])
        p1=pixels[0][E1]+ pixels[1][E1]*1j # the extreme points p_1 and p_2
        p2=pixels[0][E2]+ pixels[1][E2]*1j
        keydots=[p1,p2]
        keydots=find_keydots_c(p1,p2,pixels,image,keydots,Area, method="brightest",alpha=1)
        keyX=[]
        keyY=[]
        for j in range(0,len(keydots)):
            keyX.append(keydots[j].real)
            keyY.append(keydots[j].imag)
        
        A.plot(keyY,keyX,colors['keydots']+'.',zorder=500)
        #A.scatter(keyY, keyX, s=20, c='b', marker='s')

    
    last=len(mediatrix_data['origin'])-1
    x=[pixels[0][E1],mediatrix_data['center'].real,pixels[0][E2]]
    y=[pixels[1][E1],mediatrix_data['center'].imag,pixels[1][E2]]
    p1_vec=[pixels[0][E1],pixels[1][E1]] # the extreme points p_1 and p_2
    p2_vec=[pixels[0][E2],pixels[1][E2]]
    p3_vec=[mediatrix_vectors['center'].real,mediatrix_vectors['center'].imag]
    x_c,y_c,r=three_points_to_circle(p1_vec,p3_vec,p2_vec)
    
    if r>0:
        xy=[y_c,x_c]
        cir=Circle(xy,r,fc='none',ec='m', zorder=501)
        A.add_patch(cir)
    else:
        print "impossible to define a circle "
      

   
    xmin, xmax = xlim()
    ymin, ymax = ylim()
    min_inc_axis=40
    #x_axis_length=(xmax+1*Length)-(xmin-1*Length)
    #y_axis_length=(ymax+1*Length)-(ymin-1*Length)
    #if  x_axis_length<min_inc_axis
    A.axis("equal")
    A.set_xlim(xmin-1*Length,xmax+1*Length)
    A.set_ylim(ymin-1*Length,ymax+1*Length)    
    ylabel("Y")
    xlabel("X")
    #A.axis("equal")
    title(plot_title) 
    
    if save==True and r>0:
        savefig(out_image)
        A.clear()
        return True
    else:
        return A
Example #10
0
    def __call__(self, inputs):
        from pylab import Circle

        c = Circle((self.get_input('x'), self.get_input('y')),
                   self.get_input('radius'), **self.get_input('patch'))
        return c