コード例 #1
0
ファイル: read_garmin_gpx.py プロジェクト: yanglu16/notebook
# Plot the heartrate

# In[9]:

df['hr'].plot(figsize=(12, 4))

# Plot lon/lat with Cartopy

# In[10]:

geodetic = ccrs.Geodetic(globe=ccrs.Globe(datum='WGS84'))
b = np.array([lon.min(), lat.min(), lon.max(), lat.max()])

plt.figure(figsize=(12, 12))
# Open Source Imagery from MapQuest (max zoom = 16?)
tiler = MapQuestOpenAerial()
# Open Street Map (max zoom = 18?)
#tiler = OSM()
ax = plt.axes(projection=tiler.crs)
dx = b[2] - b[0]
dy = b[3] - b[1]
extent = (b[0] - 0.1 * dx, b[2] + 0.1 * dx, b[1] - 0.1 * dy, b[3] + 0.1 * dy)
ax.set_extent(extent, geodetic)
ax.add_image(tiler, 14)
plt.plot(lon, lat, 'm-', transform=ccrs.PlateCarree())
gl = ax.gridlines(draw_labels=True)
gl.xlabels_top = False
gl.ylabels_right = False

# In[ ]:
コード例 #2
0
def main():
    # Define the two coordinate systems with different ellipses.
    wgs84 = ccrs.PlateCarree(globe=ccrs.Globe(datum='WGS84', ellipse='WGS84'))
    sphere = ccrs.PlateCarree(
        globe=ccrs.Globe(datum='WGS84', ellipse='sphere'))

    # Define the coordinate system of the data we have from Natural Earth and
    # acquire the 1:10m physical coastline shapefile.
    geodetic = ccrs.Geodetic(globe=ccrs.Globe(datum='WGS84'))
    dataset = cartopy.feature.NaturalEarthFeature(category='physical',
                                                  name='coastline',
                                                  scale='10m')

    # Create a MapQuest map tiler instance, and use its CRS for the GeoAxes.
    tiler = MapQuestOpenAerial()
    ax = plt.axes(projection=tiler.crs)
    plt.title('The effect of incorrectly referencing the Solomon Islands')

    # Pick the area of interest. In our case, roughly the Solomon Islands, and
    # get hold of the coastlines for that area.
    extent = (155, 163, -11.5, -6)
    ax.set_extent(extent, geodetic)
    geoms = list(dataset.intersecting_geometries(extent))

    # Add the MapQuest aerial imagery at zoom level 7.
    ax.add_image(tiler, 7)

    # Transform the geodetic coordinates of the coastlines into the two
    # projections of differing ellipses.
    wgs84_geoms = [
        geom_transform(transform_fn_factory(wgs84, geodetic), geom)
        for geom in geoms
    ]
    sphere_geoms = [
        geom_transform(transform_fn_factory(sphere, geodetic), geom)
        for geom in geoms
    ]

    # Using these differently referenced geometries, assume that they are
    # both referenced to WGS84.
    ax.add_geometries(wgs84_geoms, wgs84, edgecolor='white', color='none')
    ax.add_geometries(sphere_geoms, wgs84, edgecolor='gray', color='none')

    # Create a legend for the coastlines.
    legend_artists = [
        Line([0], [0], color=color, linewidth=3) for color in ('white', 'gray')
    ]
    legend_texts = ['Correct ellipse\n(WGS84)', 'Incorrect ellipse\n(sphere)']
    legend = plt.legend(legend_artists,
                        legend_texts,
                        fancybox=True,
                        loc='lower left',
                        framealpha=0.75)
    legend.legendPatch.set_facecolor('wheat')

    # Create an inset GeoAxes showing the location of the Solomon Islands.
    sub_ax = plt.axes([0.7, 0.625, 0.2, 0.2], projection=ccrs.PlateCarree())
    sub_ax.set_extent([110, 180, -50, 10], geodetic)

    # Make a nice border around the inset axes.
    effect = Stroke(linewidth=4, foreground='wheat', alpha=0.5)
    sub_ax.outline_patch.set_path_effects([effect])

    # Add the land, coastlines and the extent of the Solomon Islands.
    sub_ax.add_feature(cartopy.feature.LAND)
    sub_ax.coastlines()
    extent_box = sgeom.box(extent[0], extent[2], extent[1], extent[3])
    sub_ax.add_geometries([extent_box],
                          ccrs.PlateCarree(),
                          color='none',
                          edgecolor='blue',
                          linewidth=2)

    plt.show()