Esempio n. 1
0
def plotmeshval(val,ixmin=None,ixmax=None,iymin=None,iymax=None,
          r_min=None,r_max=None,z_min=None,z_max=None,title=None,units=None,
          block=True):
   """
   plotmeshval(val,ixmin=<int>,ixmax=<int>,iymin=<int>,iymax=<int>
            title=<string>,units=<string>,block=<True|False>)
      Display 2-D quantity using polyfill.
      where ixmin, ixmax, iymin, and iymax are integer variables or
      expressions used to plot a portion of the grid. title is used as
      both the title and the figure name. Units are displayed in the
      side colorbar. Block default is True.

      The plot axis limits may be specified with r_rmin,r_max,z_min,z_max.
   """
   if ixmin == None: ixmin = com.nxomit
   if ixmax == None: ixmax = (com.nxm-1)
   if iymin == None: iymin = 0
   if iymax == None: iymax = (com.ny-1)
   if r_min == None: r_min = com.rm.min()
   if r_max == None: r_max = com.rm.max()
   if z_min == None: z_min = com.zm.min()
   if z_max == None: z_max = com.zm.max()
   rcdefaults()
   if title == None:
    title='Uedge'
   fig, ax = plt.subplots()

   verts = np.array([])
   z = np.array([])
   for ix in range(ixmax-ixmin+1):
       for iy in range(iymax-iymin+1):
           v = []
           v.append([com.rm[ix,iy,1],com.zm[ix,iy,1]])
           v.append([com.rm[ix,iy,2],com.zm[ix,iy,2]])
           v.append([com.rm[ix,iy,4],com.zm[ix,iy,4]])
           v.append([com.rm[ix,iy,3],com.zm[ix,iy,3]])
           verts = np.append(verts,v)
           z = np.append(z,val[ix,iy])
   verts = verts.reshape(len(z),4,2)
   ax.set_title(title)
   ax.set_ylabel('Z (m)')
   ax.set_xlabel('R (m)')
   ax.set_aspect('equal')

   coll = PolyCollection(verts,array=z,cmap=cm.jet,edgecolors='face')
   ax.add_collection(coll)
   ax.autoscale_view()
   cbar = fig.colorbar(coll,ax=ax)
   #if units != None: cbar.ax.set_ylabel(units,rotation=-90,va='bottom')
   if units != None: cbar.ax.set_ylabel(units,va='bottom')
   plt.ylim(z_min,z_max)
   plt.xlim(r_min,r_max)

   #plt.show(block=block)
   plt.ion()
   plt.show()
   plt.pause(0.001)
Esempio n. 2
0
def symbols(x, y, symbols, size, axes=None, units='inches'):
    """
    Draws fixed-size symbols.

    See :mod:`iris.symbols` for available symbols.

    Args:

    * x: iterable
        The x coordinates where the symbols will be plotted.

    * y: iterable
        The y coordinates where the symbols will be plotted.

    * symbols: iterable
        The symbols (from :mod:`iris.symbols`) to plot.

    * size: float
        The symbol size in `units`.

    Kwargs:

    * axes: the :class:`matplotlib.axes.Axes` to use for drawing.
        Defaults to the current axes if none provided.

    * units: ['inches', 'points']
        The unit for the symbol size.

    """
    if axes is None:
        axes = plt.gca()

    offsets = np.array(list(zip(x, y)))

    # XXX "match_original" doesn't work ... so brute-force it instead.
    #   PatchCollection constructor ignores all non-style keywords when using
    #   match_original
    #   See matplotlib.collections.PatchCollection.__init__
    #   Specifically matplotlib/collections line 1053
    # pc = PatchCollection(symbols, offsets=offsets, transOffset=ax.transData,
    #                      match_original=True)
    facecolors = [p.get_facecolor() for p in symbols]
    edgecolors = [p.get_edgecolor() for p in symbols]
    linewidths = [p.get_linewidth() for p in symbols]

    pc = mpl_collections.PatchCollection(symbols,
                                         offsets=offsets,
                                         transOffset=axes.transData,
                                         facecolors=facecolors,
                                         edgecolors=edgecolors,
                                         linewidths=linewidths)

    if units == 'inches':
        scale = axes.figure.dpi
    elif units == 'points':
        scale = axes.figure.dpi / 72.0
    else:
        raise ValueError("Unrecognised units: '%s'" % units)
    pc.set_transform(mpl_transforms.Affine2D().scale(0.5 * size * scale))

    axes.add_collection(pc)
    axes.autoscale_view()
Esempio n. 3
0
def symbols(x, y, symbols, size, axes=None, units='inches'):
    """
    Draws fixed-size symbols.

    See :mod:`iris.symbols` for available symbols.

    Args:

    * x: iterable
        The x coordinates where the symbols will be plotted.

    * y: iterable
        The y coordinates where the symbols will be plotted.

    * symbols: iterable
        The symbols (from :mod:`iris.symbols`) to plot.

    * size: float
        The symbol size in `units`.

    Kwargs:

    * axes: the :class:`matplotlib.axes.Axes` to use for drawing.
        Defaults to the current axes if none provided.

    * units: ['inches', 'points']
        The unit for the symbol size.

    """
    if axes is None:
        axes = plt.gca()

    offsets = np.array(list(zip(x, y)))

    # XXX "match_original" doesn't work ... so brute-force it instead.
    #   PatchCollection constructor ignores all non-style keywords when using
    #   match_original
    #   See matplotlib.collections.PatchCollection.__init__
    #   Specifically matplotlib/collections line 1053
    # pc = PatchCollection(symbols, offsets=offsets, transOffset=ax.transData,
    #                      match_original=True)
    facecolors = [p.get_facecolor() for p in symbols]
    edgecolors = [p.get_edgecolor() for p in symbols]
    linewidths = [p.get_linewidth() for p in symbols]

    pc = mpl_collections.PatchCollection(symbols, offsets=offsets,
                                         transOffset=axes.transData,
                                         facecolors=facecolors,
                                         edgecolors=edgecolors,
                                         linewidths=linewidths)

    if units == 'inches':
        scale = axes.figure.dpi
    elif units == 'points':
        scale = axes.figure.dpi / 72.0
    else:
        raise ValueError("Unrecognised units: '%s'" % units)
    pc.set_transform(mpl_transforms.Affine2D().scale(0.5 * size * scale))

    axes.add_collection(pc)
    axes.autoscale_view()