Python matplotlib.pyplot.quiverkey() Examples

The following are code examples for showing how to use matplotlib.pyplot.quiverkey(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: vmap   Author: dshean   File: disp2v.py    MIT License 6 votes vote down vote up
def plotvec(h, v):
    #Probably want to smooth h and v here, or at least filter outliers
    #Interpolation or hole filling would also help with lots of nodata holes 
    #Compute stats within window centered on X and Y
    nvec = np.array([40,40], dtype=np.float)
    stride = np.round(min(h.shape/nvec)).astype('int')
    X,Y = np.meshgrid(np.arange(0,h.shape[1],stride),np.arange(0,h.shape[0],stride))
    h_sub = h[::stride,::stride]
    v_sub = v[::stride,::stride]
    norm = False
    if norm:
        m_sub = np.ma.sqrt(h_sub**2+v_sub**2)
        h_sub /= m_sub
        v_sub /= m_sub
    Q = plt.quiver(X,Y,h_sub,v_sub,pivot='middle',color='white')
    #Add quiver key
    #scale = float(Q.scale)
    #lbl = str(np.round(Q.scale).astype(int)) + r'$\frac{m}{s}$'
    #lbl = '%i m/s' % np.around(scale, decimals=0).astype(int) 
    #qk = plt.quiverkey(Q, 0.05, 0.05, 1, lbl, labelpos='N', fontproperties={'weight':'bold'}) 
Example 2
Project: gimic   Author: qmcurrents   File: plot.py    GNU General Public License v2.0 6 votes vote down vote up
def vector_plot(self, fname=None, k=0):
        if not isinstance(self.field, VectorField):
            raise TypeError('Not a vector field')
        fig = plt.figure()
        x = self.grid.get_axis(0).get_points()
        y = self.grid.get_axis(1).get_points()
        x, y = np.meshgrid(x, y)
        u, v, w = self.field.get_field(k)
        q = plt.quiver(v, u)
#        qk = plt.quiverkey(q, 0.5, 0.92, 2, r'$2 \frac{m}{s}$', labelpos='W',
#                               fontproperties={'weight': 'bold'})
        l,r,b,t = plt.axis()
        dx, dy = r-l, t-b
        plt.axis([l-0.05*dx, r+0.05*dx, b-0.05*dy, t+0.05*dy])

        plt.title('Minimal vector plot')

        if fname is not None:
            plt.savefig(fname)
        else:
            plt.show()