I’m looking for a way to plot filled rectangles on a Basemap. I could easily draw the rectangle’s edges using the drawgreatcircle method, but I cannot find a way to actually fill these rectangles (specifying color and alpha).
I’m looking for a way to plot filled rectangles on a Basemap. I could
Share
You can add a matplotlib.patches.Polygon() directly to your axes. The question is whether you want your rectangles defined the plot coordinates (straight lines on the plot) or in map coordinates (great circles on the plot). Either way, you specify vertices in map coordinates and then transform them to plot coordinates by calling the Basemap instance (
m()in the below example), build a Polygon yourself, and add it manually to the axes to be rendered.For rectangles defined in plot coordinates, here’s an example:
For rectangles defined in map coordinates, use the same approach, but interpolate your line in map space before transforming to plot coordinates. For each line segment, you’ll have to do:
Then transform these map coordinates to plot coordinates (as above, with
m()) and again create a Polygon with the plot coordinates.