I need to know how to update the axes of a plot after creation. I saw in the matplotlib documentation here.
I have tried the following code:
ax.update(ax.properties())
but I get the following error:
Traceback (most recent call last):
File "<ipython-input-127-e6624b1841f4>", line 1, in <module>
ax.update(ax.properties())
File "C:\Users\cjmar\Anaconda3\lib\site-packages\matplotlib\artist.py", line 974, in update
ret = [_update_property(self, k, v) for k, v in props.items()]
File "C:\Users\cjmar\Anaconda3\lib\site-packages\matplotlib\artist.py", line 974, in <listcomp>
ret = [_update_property(self, k, v) for k, v in props.items()]
File "C:\Users\cjmar\Anaconda3\lib\site-packages\matplotlib\artist.py", line 970, in _update_property
.format(type(self).__name__, k))
AttributeError: 'GeoAxesSubplot' object has no property 'children'
and yet examining ax.properties()
there is indeed a 'children' key there. Not sure what is going on. I know that cartopy seems to override the GeoAxes
class, however, there doesn't seem to be anything overloaded with respect to the update method.
Some example code. Best to run this in an iPython console so that you can access the ax
object while the plot is still showing. May require a plt.show()
at the bottom. I use Spyder, which doesn't require this.
import os
import sys
import matplotlib.pyplot as plt
import matplotlib
import mpl_toolkits
import numpy as np
import cartopy
import cartopy.crs as ccrs
fig = plt.figure()
ax = plt.axes(projection=ccrs.NorthPolarStereo())
ax.stock_img()
ny_lon, ny_lat = -75, 43
delhi_lon, delhi_lat = 77.23, 28.61
plt.plot([ny_lon, delhi_lon], [ny_lat, delhi_lat],
color='blue', linewidth=2, marker='o',
transform=ccrs.Geodetic(),
)
plt.plot([ny_lon, delhi_lon], [ny_lat, delhi_lat],
color='gray', linestyle='--',
transform=ccrs.PlateCarree(),
)
ax.add_patch(matplotlib.patches.Polygon([[0,0],[20,0],[20,20],[0,20]],
fill = False,color='g',ls='--',
transform=ccrs.PlateCarree()))
ax.add_patch(matplotlib.patches.Circle([30,30],radius=10,color='g',ls='--',
transform=ccrs.PlateCarree()))
plt.text(ny_lon - 3, ny_lat - 12, 'New York',
horizontalalignment='right',
transform=ccrs.Geodetic())
plt.text(delhi_lon + 3, delhi_lat - 12, 'Delhi',
horizontalalignment='left',
transform=ccrs.Geodetic())
# ax.set_extent([-180,180,-90,90])
ax.set_global()
How do I utilize this method properly?
EDIT: This question is in direct correlation to this other question asked by me. here
But the questions are indeed different, as this question is asking how to use the method, and that question is asking how to update an axes projection.