Ejemplo 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)
Ejemplo 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()
Ejemplo 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()
Ejemplo n.º 4
0
def draw_fancy_lanelet_map(laneletmap, axes):
    set_visible_area(laneletmap, axes)
    unknown_linestring_types = list()

    for ls in laneletmap.lineStringLayer:
        if "type" not in ls.attributes.keys():
            raise RuntimeError("ID " + str(ls.id) +
                               ": Linestring type must be specified")
        elif ls.attributes["type"] == "curbstone":
            type_dict = dict(color="black", linewidth=1, zorder=10)
        elif ls.attributes["type"] == "line_thin":
            if "subtype" in ls.attributes.keys(
            ) and ls.attributes["subtype"] == "dashed":
                type_dict = dict(color="white",
                                 linewidth=1,
                                 zorder=10,
                                 dashes=[10, 10])
            else:
                type_dict = dict(color="white", linewidth=1, zorder=10)
        elif ls.attributes["type"] == "line_thick":
            if "subtype" in ls.attributes.keys(
            ) and ls.attributes["subtype"] == "dashed":
                type_dict = dict(color="white",
                                 linewidth=2,
                                 zorder=10,
                                 dashes=[10, 10])
            else:
                type_dict = dict(color="white", linewidth=2, zorder=10)
        elif ls.attributes["type"] == "pedestrian_marking":
            type_dict = dict(color="white",
                             linewidth=1,
                             zorder=10,
                             dashes=[5, 10])
        elif ls.attributes["type"] == "bike_marking":
            type_dict = dict(color="white",
                             linewidth=1,
                             zorder=10,
                             dashes=[5, 10])
        elif ls.attributes["type"] == "stop_line":
            type_dict = dict(color="white", linewidth=3, zorder=10)
        elif ls.attributes["type"] == "virtual":
            type_dict = dict(color="blue",
                             linewidth=1,
                             zorder=10,
                             dashes=[2, 5])
        elif ls.attributes["type"] == "road_border":
            type_dict = dict(color="black", linewidth=1, zorder=10)
        elif ls.attributes["type"] == "guard_rail":
            type_dict = dict(color="black", linewidth=1, zorder=10)
        elif ls.attributes["type"] == "traffic_sign":
            continue
        else:
            if ls.attributes["type"] not in unknown_linestring_types:
                unknown_linestring_types.append(ls.attributes["type"])
            continue
        ls_points_x = [pt.x for pt in ls]
        ls_points_y = [pt.y for pt in ls]
        plt.plot(ls_points_x, ls_points_y, **type_dict)

    if len(unknown_linestring_types) != 0:
        print("Found the following unknown types, did not plot them: " +
              str(unknown_linestring_types))

    lanelets = []
    for ll in laneletmap.laneletLayer:
        points = [[pt.x, pt.y] for pt in ll.polygon2d()]
        polygon = Polygon(points, True)
        lanelets.append(polygon)

    ll_patches = PatchCollection(lanelets,
                                 facecolors="lightgray",
                                 edgecolors="None",
                                 zorder=5)
    axes.add_collection(ll_patches)
    if len(laneletmap.laneletLayer) == 0:
        axes.patch.set_facecolor('lightgrey')
    areas = []
    for area in laneletmap.areaLayer:
        if area.attributes["subtype"] == "keepout":
            points = [[pt.x, pt.y] for pt in area.outerBoundPolygon()]
            polygon = Polygon(points, True)
            areas.append(polygon)
    area_patches = PatchCollection(areas,
                                   facecolors="darkgray",
                                   edgecolors="None",
                                   zorder=5)
    axes.add_collection(area_patches)