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)
def set_visible_area(point_dict, axes): min_x = 10e9 min_y = 10e9 max_x = -10e9 max_y = -10e9 for id, point in dict_utils.get_item_iterator(point_dict): min_x = min(point.x, min_x) min_y = min(point.y, min_y) max_x = max(point.x, max_x) max_y = max(point.y, max_y) axes.set_aspect('equal', adjustable='box') axes.set_xlim([min_x - 10, max_x + 10]) axes.set_ylim([min_y - 10, max_y + 10])
def set_visible_area(laneletmap, axes): min_x = 10e9 min_y = 10e9 max_x = -10e9 max_y = -10e9 for point in laneletmap.pointLayer: min_x = min(point.x, min_x) min_y = min(point.y, min_y) max_x = max(point.x, max_x) max_y = max(point.y, max_y) axes.set_aspect('equal', adjustable='box') axes.set_xlim([min_x - 10, max_x + 10]) axes.set_ylim([min_y - 10, max_y + 10])
theta = np.linspace(-4 * np.pi, 4 * np.pi, 100) z = np.linspace(-2, 2, 100) r = z**2 + 1 x = r * np.sin(theta) y = r * np.cos(theta) ax.plot(r_ECI[:, 0] / 1000, r_ECI[:, 1] / 1000, r_ECI[:, 2] / 1000, label='Orbital Position', color='k') # Sphere to represent Earth # Make data u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) x1 = rEarth / 1000 * np.outer(np.cos(u), np.sin(v)) y1 = rEarth / 1000 * np.outer(np.sin(u), np.sin(v)) z1 = rEarth / 1000 * np.outer(np.ones(np.size(u)), np.cos(v)) # Plot the surface ax.plot_surface(x1, y1, z1, cmap='GnBu') # Legend and labels ax.legend() ax.set_xlabel('X Pos (km)') ax.set_ylabel('Y Pos (km)') ax.set_zlabel('Z Pos (km)') ax.set_aspect('equal') plt.show()
def draw_map_without_lanelet(filename, axes, lat_origin, lon_origin): assert isinstance(axes, matplotlib.axes.Axes) axes.set_aspect('equal', adjustable='box') axes.patch.set_facecolor('lightgrey') projector = LL2XYProjector(lat_origin, lon_origin) e = xml.parse(filename).getroot() point_dict = dict() for node in e.findall("node"): point = Point() point.x, point.y = projector.latlon2xy(float(node.get('lat')), float(node.get('lon'))) point_dict[int(node.get('id'))] = point set_visible_area(point_dict, axes) unknown_linestring_types = list() for way in e.findall('way'): way_type = get_type(way) if way_type is None: raise RuntimeError("Linestring type must be specified") elif way_type == "curbstone": type_dict = dict(color="black", linewidth=1, zorder=10) elif way_type == "line_thin": way_subtype = get_subtype(way) if way_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 way_type == "line_thick": way_subtype = get_subtype(way) if way_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 way_type == "pedestrian_marking": type_dict = dict(color="white", linewidth=1, zorder=10, dashes=[5, 10]) elif way_type == "bike_marking": type_dict = dict(color="white", linewidth=1, zorder=10, dashes=[5, 10]) elif way_type == "stop_line": type_dict = dict(color="white", linewidth=3, zorder=10) elif way_type == "virtual": type_dict = dict(color="blue", linewidth=1, zorder=10, dashes=[1, 1], alpha=0.2) elif way_type == "road_border": type_dict = dict(color="black", linewidth=1, zorder=10) elif way_type == "guard_rail": type_dict = dict(color="black", linewidth=1, zorder=10) elif way_type == "traffic_sign": continue else: if way_type not in unknown_linestring_types: unknown_linestring_types.append(way_type) continue x_list, y_list = get_x_y_lists(way, point_dict) plt.plot(x_list, y_list, **type_dict) if len(unknown_linestring_types) != 0: print("Found the following unknown types, did not plot them: " + str(unknown_linestring_types))
def draw_map_without_lanelet(filename, axes, lat_origin, lon_origin, scene=''): assert isinstance(axes, matplotlib.axes.Axes) axes.set_aspect('equal', adjustable='box') axes.patch.set_facecolor('white') projector = LL2XYProjector(lat_origin, lon_origin) e = xml.parse(filename).getroot() point_dict = dict() for node in e.findall("node"): point = Point() point.x, point.y = projector.latlon2xy(float(node.get('lat')), float(node.get('lon'))) point_dict[int(node.get('id'))] = point min_x, max_x, min_y, max_y = set_visible_area(point_dict, axes) unknown_linestring_types = list() road_points = [] for way in e.findall('way'): way_type = get_type(way) if way_type is None: raise RuntimeError("Linestring type must be specified") elif way_type == "curbstone": type_dict = dict(color="black", linewidth=1, zorder=10) elif way_type == "line_thin": way_subtype = get_subtype(way) if way_subtype == "dashed": type_dict = dict(color="blue", linewidth=1, zorder=10, dashes=[10, 10]) else: type_dict = dict(color="blue", linewidth=1, zorder=10) elif way_type == "line_thick": way_subtype = get_subtype(way) if way_subtype == "dashed": type_dict = dict(color="blue", linewidth=2, zorder=10, dashes=[10, 10]) else: type_dict = dict(color="blue", linewidth=2, zorder=10) elif way_type == "pedestrian_marking": type_dict = dict(color="red", linewidth=1, zorder=10) elif way_type == "bike_marking": type_dict = dict(color="blue", linewidth=1, zorder=10, dashes=[5, 10]) elif way_type == "stop_line": type_dict = dict(color="red", linewidth=3, zorder=10) elif way_type == "virtual": pass type_dict = dict(color="blue", linewidth=1, zorder=10, dashes=[2, 5]) elif way_type == "road_border": pass type_dict = dict(color="black", linewidth=1, zorder=10) elif way_type == "guard_rail": pass type_dict = dict(color="black", linewidth=1, zorder=10) elif way_type == "traffic_sign": continue else: if way_type not in unknown_linestring_types: unknown_linestring_types.append(way_type) continue x_list, y_list = get_x_y_lists(way, point_dict) if way_type not in ["virtual", "road_border"]: plt.plot(x_list, y_list, **type_dict) if way_type == 'curbstone': xy = [(x, y) for x, y in zip(x_list, y_list)] flag = 0 for i, xy0 in enumerate(road_points): if dis(xy[0], xy0[-1]) < 2: road_points[i] += xy flag = 1 break elif dis(xy0[0], xy[-1]) < 2: road_points[i] = xy + xy0 flag = 1 break elif dis(xy[0], xy0[0]) < 2: road_points[i] = xy[::-1] + xy0 flag = 1 break elif dis(xy[-1], xy0[-1]) < 2: road_points[i] = xy0 + xy[::-1] flag = 1 break if flag == 0: road_points.append(xy) road_points = link_road(road_points) mdis = 25 for i, road in enumerate(road_points): # print(road[0][0], min_x, max_x) plt.scatter(road[0][0], road[0][1], zorder=30) plt.scatter(road[-1][0], road[-1][1], zorder=30, c='r', alpha=0.5) pre = None post = None corner_x = None corner_y = None if dis(road[0], road[-1]) < 5: continue left1 = road[0][0] - min_x right1 = max_x - road[0][0] top1 = max_y - road[0][1] bottom1 = road[0][1] - min_y min_dis1 = min([left1, right1, top1, bottom1]) left2 = road[-1][0] - min_x right2 = max_x - road[-1][0] top2 = max_y - road[-1][1] bottom2 = road[-1][1] - min_y min_dis2 = min([left2, right2, top2, bottom2]) if abs((road[1][1] - road[0][1]) / (road[1][0] - road[0][0])) > 10: if road[0][1] > road[1][1]: corner_y = max_y if top1 < mdis: x = (road[1][0] - road[0][0]) / ( road[1][1] - road[0][1]) * (corner_y - road[1][1]) + road[1][0] pre = [[x, max_y]] else: pre = [[road[0][0], max_y]] else: corner_y = min_y if bottom1 < mdis: x = (road[1][0] - road[0][0]) / ( road[1][1] - road[0][1]) * (corner_y - road[1][1]) + road[1][0] pre = [[x, min_y]] else: pre = [[road[0][0], min_y]] else: if left1 == min_dis1: corner_x = min_x if left1 < mdis: y = (road[1][1] - road[0][1]) / ( road[1][0] - road[0][0]) * (corner_x - road[1][0]) + road[1][1] pre = [[min_x, y]] else: pre = [[min_x, road[0][1]]] elif right1 == min_dis1: corner_x = max_x if right1 < mdis: y = (road[1][1] - road[0][1]) / ( road[1][0] - road[0][0]) * (corner_x - road[1][0]) + road[1][1] pre = [[max_x, y]] else: pre = [[max_x, road[0][1]]] elif bottom1 == min_dis1: corner_y = min_y if bottom1 < mdis: x = (road[1][0] - road[0][0]) / ( road[1][1] - road[0][1]) * (corner_y - road[1][1]) + road[1][0] pre = [[x, min_y]] else: pre = [[road[0][0], min_y]] elif top1 == min_dis1: corner_y = max_y if top1 < mdis: x = (road[1][0] - road[0][0]) / ( road[1][1] - road[0][1]) * (corner_y - road[1][1]) + road[1][0] pre = [[x, max_y]] else: pre = [[road[0][0], max_y]] # last if abs((road[-2][1] - road[-1][1]) / (road[-2][0] - road[-1][0])) > 10: if road[-1][1] > road[-2][1]: corner_y = max_y if top2 < mdis: x = (road[-2][0] - road[-1][0]) / (road[-2][1] - road[-1][1]) * ( corner_y - road[-2][1]) + road[-2][0] post = [[x, max_y]] else: post = [[road[-1][0], max_y]] else: corner_y = min_y if bottom2 < mdis: x = (road[-2][0] - road[-1][0]) / (road[-2][1] - road[-1][1]) * ( corner_y - road[-2][1]) + road[-2][0] post = [[x, min_y]] else: post = [[road[-1][0], min_y]] else: if left2 == min_dis2: corner_x = min_x if left2 < mdis: y = (road[-2][1] - road[-1][1]) / (road[-2][0] - road[-1][0]) * ( corner_x - road[-2][0]) + road[-2][1] post = [[min_x, y]] else: post = [[min_x, road[-1][1]]] elif right2 == min_dis2: corner_x = max_x if right2 < mdis: y = (road[-2][1] - road[-1][1]) / (road[-2][0] - road[-1][0]) * ( corner_x - road[-2][0]) + road[-2][1] post = [[max_x, y]] else: post = [[max_x, road[-1][1]]] elif bottom2 == min_dis2: corner_y = min_y if bottom2 < mdis: x = (road[-2][0] - road[-1][0]) / (road[-2][1] - road[-1][1]) * ( corner_y - road[-2][1]) + road[-2][0] post = [[x, min_y]] else: post = [[road[-1][0], min_y]] elif top2 == min_dis2: corner_y = max_y if top2 < mdis: x = (road[-2][0] - road[-1][0]) / (road[-2][1] - road[-1][1]) * ( corner_y - road[-2][1]) + road[-2][0] post = [[x, max_y]] else: post = [[road[-1][0], max_y]] if pre: road_points[i] = pre + road_points[i] if post: road_points[i] = road_points[i] + post if pre and post: road_points[i] += [[corner_x, corner_y]] for xy in road_points: area = matplotlib.patches.Polygon(xy, closed=True, color='lightgrey') axes.add_patch(area) if len(unknown_linestring_types) != 0: print("Found the following unknown types, did not plot them: " + str(unknown_linestring_types))
ax.plot([-10, 10], [0, 0], "b--") ax.plot([0, 0], [-10, 10], "b--") v3 = Vector(6, 6) x = 31 / 180 rm = Matrix([cos(x), sin(x)], [-sin(x), cos(x)]) print(rm) v3.plot(figure=ax) colours = ["black"] v4 = v3 * rm v5 = v4 * rm v6 = v5 * rm for _ in range(10): v4.plot(ch(colours), figure=ax) v4 *= rm #v5.plot("pink", figure = ax) #v6.plot("green", figure = ax) ax.set_aspect(1) plt.legend(["x Axis", "y Axis", "Original", "Rotations"]) plt.show()