本文整理汇总了Python中matplotlib.axes.Axes.annotate方法的典型用法代码示例。如果您正苦于以下问题:Python Axes.annotate方法的具体用法?Python Axes.annotate怎么用?Python Axes.annotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.axes.Axes
的用法示例。
在下文中一共展示了Axes.annotate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_station_positions
# 需要导入模块: from matplotlib.axes import Axes [as 别名]
# 或者: from matplotlib.axes.Axes import annotate [as 别名]
def plot_station_positions(directions_file_path: Path, stations: list, ax: Axes, grid_config: GridConfig=default_domains.bc_mh_044,
save_upstream_boundaries_to_shp=False):
with Dataset(str(directions_file_path)) as ds:
flow_dirs = ds.variables["flow_direction_value"][:]
flow_acc_area = ds.variables["accumulation_area"][:]
lons_2d, lats_2d = [ds.variables[k][:] for k in ["lon", "lat"]]
basemap, reg_of_interest = grid_config.get_basemap_using_shape_with_polygons_of_interest(lons_2d, lats_2d,
shp_path=default_domains.MH_BASINS_PATH,
resolution="i")
cell_manager = CellManager(flow_dirs, lons2d=lons_2d, lats2d=lats_2d, accumulation_area_km2=flow_acc_area)
station_to_model_point = cell_manager.get_model_points_for_stations(station_list=stations, nneighbours=8)
#####
xx, yy = basemap(lons_2d, lats_2d)
upstream_edges = cell_manager.get_upstream_polygons_for_points(
model_point_list=list(station_to_model_point.values()), xx=xx, yy=yy)
upstream_edges_latlon = cell_manager.get_upstream_polygons_for_points(
model_point_list=list(station_to_model_point.values()), xx=lons_2d, yy=lats_2d)
plot_utils.draw_upstream_area_bounds(ax, upstream_edges=upstream_edges, color="r", linewidth=0.6)
if save_upstream_boundaries_to_shp:
plot_utils.save_to_shape_file(upstream_edges_latlon, folder_path="mh/engage_report/upstream_stations_areas/mh_{}".format(grid_config.dx), in_proj=None)
basemap.drawrivers(linewidth=0.2)
basemap.drawstates(linewidth=0.1)
basemap.drawcountries(linewidth=0.1)
basemap.drawcoastlines(linewidth=0.2)
pos_ids, lons_pos, lats_pos = [], [], []
pos_labels = []
legend_lines = []
for i, (s, mp) in enumerate(sorted(station_to_model_point.items(), key=lambda p: p[0].latitude, reverse=True), start=1):
pos_ids.append(s.id)
pos_labels.append(i)
lons_pos.append(mp.longitude)
lats_pos.append(mp.latitude)
legend_lines.append("{}: {}".format(i, s.id))
xm, ym = basemap(lons_pos, lats_pos)
ax.scatter(xm, ym, c="g", s=20)
for txt, x1, y1, pos_label in zip(pos_ids, xm, ym, pos_labels):
ax.annotate(pos_label, xy=(x1, y1))
at = AnchoredText("\n".join(legend_lines), prop=dict(size=8), frameon=True, loc=1)
at.patch.set_boxstyle("round,pad=0.,rounding_size=0.2")
ax.add_artist(at)