cartopy

Cartopy behavior when plotting projected data

99封情书 提交于 2019-12-05 09:55:53
I am using cartopy to draw my maps. Its a great tool! For some of my data I have the problem that the data is not properly mapped around 0deg or the dateline. See the example below. I know the same feature from matplotlib.basemap, where it can be solved by using the add_cyclic routine. I wondered if somebody can recommend how to best fix this problem in cartopy. Thanks! Alex When plotting global data like this you will always need to add a cyclic point to your input data and coordinate. I don't believe Cartopy currently includes a function to do this for you, but you can do it yourself quite

Cartopy: axis label - workaround

浪子不回头ぞ 提交于 2019-12-05 09:38:41
I am looking for a workaround to add x and y axis ticks and labels to a Cartopy map in Lambert projection. The solution I have come up with is just an approximation which will yield worse results for larger maps: It involves transforming desired tick locations to map projection using the transform_points method. For this I use the median longitude (or latitude) of my y axis (or x axis) together with the desired latitudes (or longitudes) tick positions to compute map projection coordinates. See code below. Thus, I am assuming constant longitudes along the y-axis (latitudes along the x-axis),

Make colorbar legend in Matplotlib/Cartopy

狂风中的少年 提交于 2019-12-05 08:22:14
I've made a geographical heatmap using cartopy and matplotlib, of the number of users of my app, but am having trouble adding a colorbar legend: import cartopy.crs as ccrs import cartopy.io.shapereader as shpreader import matplotlib.pyplot as plt import matplotlib as mpl import numpy as np cmap = mpl.cm.Blues # Countries is a dictionary of {"country_name": number of users}, for example countries = {"United States": 100, "Canada": 50, "China": 10} max_users = float(max(countries.values())) shapename = 'admin_0_countries' countries_shp = shpreader.natural_earth(resolution='110m', category=

Animate a point moving along path between two points

北战南征 提交于 2019-12-05 06:10:30
问题 I want to animate a point moving along a path from one location to another on the map. For example, I drawn a path from New York to New Delhi, using Geodetic transform. Eg. taken from docs Adding data to the map plt.plot([ny_lon, delhi_lon], [ny_lat, delhi_lat], color='blue', linewidth=2, marker='o', transform=ccrs.Geodetic(), ) Now i want to move a point along this path. My idea was to somehow get some (say 50) points, along the path and plot a marker on each point for each frame. But I am

Geodesic buffering in python

China☆狼群 提交于 2019-12-04 08:29:09
Given land polygons as a Shapely MultiPolygon , I want to find the (Multi-)Polygon that represents the e.g. 12 nautical mile buffer around the coastlines. Using the Shapely buffer method does not work since it uses euclidean calculations. Can somebody tell me how to calculate geodesic buffers in python? This is not a shapely problem, since shapely explicitly tells in its documentation that the library is for planar computation only. Nevertheless, in order to answer your question, you should specify the coordinate systems you are using for your multipolygons. Assuming you are using WGS84

Polygon containment test in matplotlib artist

我们两清 提交于 2019-12-03 21:43:33
I have the following code, gathered initially from here. , which uses matplotlib, shapely, cartopy to draw a world map. When a click is made, I need to determine on which country it was made. I am able to add a pick_event callback to the canvas, however, it is called on every artist.(cartopy.mpl.feature_artist.FeatureArtist, which corresponds to a country). Given an artist and a mouse event with x, y coordinates, how can I determine containment? I've tried artist.get_clip_box().contains , but it is not really a polygon, rather a plain rectangle. The default containment test for the

Animate a point moving along path between two points

前提是你 提交于 2019-12-03 21:18:28
I want to animate a point moving along a path from one location to another on the map. For example, I drawn a path from New York to New Delhi, using Geodetic transform. Eg. taken from docs Adding data to the map plt.plot([ny_lon, delhi_lon], [ny_lat, delhi_lat], color='blue', linewidth=2, marker='o', transform=ccrs.Geodetic(), ) Now i want to move a point along this path. My idea was to somehow get some (say 50) points, along the path and plot a marker on each point for each frame. But I am not able to find a way to get the points on the path. I found a function transform_points under class

How to add a point-feature shapefile to map using cartopy

风流意气都作罢 提交于 2019-12-03 14:25:27
I have two shapefiles. One is a point feature shapefile, named "point.shp", the other is a polygon shapefile named "polygon.shp". Both I want to add to a map using cartopy. I managed to add the "polygon.shp", but failed with the "point.shp". Here's my code: import matplotlib.pyplot as plt from cartopy import crs from cartopy.io.shapereader import Reader from cartopy.feature import ShapelyFeature ax = plt.axes(projection=crs.PlateCarree()) # add the polygon file, worked ax.add_geometries(Reader("polygon.shp").geometries(), crs.PlateCarree(), facecolor='w') # or(also worked): ax.add_feature

How do I change matplotlib's subplot projection of an existing axis?

你。 提交于 2019-12-03 05:23:26
I'm trying to construct a simple function that takes a subplot instance ( matplotlib.axes._subplots.AxesSubplot ) and transforms its projection to another projection, for example, to one of the cartopy.crs.CRS projections. The idea looks something like this import cartopy.crs as ccrs import matplotlib.pyplot as plt def make_ax_map(ax, projection=ccrs.PlateCarree()): # set ax projection to the specified projection ... # other fancy formatting ax2.coastlines() ... # Create a grid of plots fig, (ax1, ax2) = plt.subplots(ncols=2) # the first subplot remains unchanged ax1.plot(np.random.rand(10)) #

Matplotlib projection remove margin

耗尽温柔 提交于 2019-12-02 07:02:40
Here's an image of US counties, created on top of ax = plt.axes(projection=ccrs.LambertConformal()) ax.set_extent([-120, -70, 20, 50], ccrs.Geodetic()) In the "live" figure one can see with plt.show() , there's a large gray area around the figure. Here you can (not) see it via the white padding. So I thought I could zoom in a bit more: ax.set_extent([-120, -70, 20, 40], ccrs.Geodetic()) And then this happened: While there is still white margin/padding around the figure, it's suddenly cropped. The "live image" also is showing me some white margin that is apparently placed around the projection.