  C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD # Cartopy: Can't add features to geo axes (no errors or warnings)  » python » Cartopy: Can't add features to geo axes (no errors or warnings)

By : user2950498
Date : November 17 2020, 11:55 AM
hope this fix your issue I wasn't getting this error previously, but when I ran the code from an IPython notebook for some reason I got this error HTTPError: HTTP Error 404: Not Found
What I ended up having to do was change line 264 in shapereader.py from: code :
`````` _NE_URL_TEMPLATE = ('http://www.nacis.org/naturalearth/{resolution}'
'/{category}/ne_{resolution}_{name}.zip')
``````
``````_NE_URL_TEMPLATE = ('http://www.naturalearthdata.com/'
'/{category}/ne_{resolution}_{name}.zip')
`````` ## Drawing lines between cartopy axes

By : E Dgz
Date : March 29 2020, 07:55 AM
may help you . Not easily AFAIK, as you essentially want to define one point in one CS and the other in another (BlendedGenericTransform allows you to define your xs in one CS and ys in another, but not individual points).
As a result, the only solution I know of is to construct a transform which expects a certain number of points to transform. I've implemented a 2 point transformation class which transforms the first point given the first transform, and the second point with the other transform:
code :
``````import matplotlib.transform as mtrans

class TwoPointTransformer(mtrans.Transform):
is_affine = False
has_inverse = False

def __init__(self, first_point_transform, second_point_transform):
self.first_point_transform = first_point_transform
self.second_point_transform = second_point_transform
return mtrans.Transform.__init__(self)

def transform_non_affine(self, values):
if values.shape != (2, 2):
raise ValueError('The TwoPointTransformer can only handle '
'vectors of 2 points.')
result = self.first_point_transform.transform_affine(values)
second_values = self.second_point_transform.transform_affine(values)
result[1, :] = second_values[1, :]
return result
``````
``````line = plt.Line2D(xdata=(-45, 0), ydata=(-15, 0),
transform=TwoPointTransformer(ax1.transData, ax2.transAxes))
``````
``````fig.canvas.mpl_connect('resize_event', lambda v: line.recache())
`````` ## Cartopy subplot ticks & axes box line formatting

By : user2401560
Date : March 29 2020, 07:55 AM
Hope that helps Unfortunately, I don't think there is any control provided for either of these.
Regarding rotated ticks: With some care you can add axis ticks, and rotate those with usual "axes.set_ticklabels(... rotation=X)". But the gridline labels are not ticks, and you can't do this -- you can only control the position and formatting (via the exposed ticker and formatter objects). ## Polar plot axes labels for Cartopy

By : May
Date : March 29 2020, 07:55 AM
I wish this helpful for you No, unfortunately there is no support for this at present. Only the simplest and commonest forms have so far been coded, because the general case is just hard. For example, specifically regarding polar plots .. (1) in some places gridlines converge so it may be necessary to label only certain ones, and (2) some gridlines (e.g. meridians) can be entirely inside the plot area.
As of now, this is really just waiting for someone to take it on. ## Correct placement of colorbar relative to geo axes (cartopy)

By : jaysee
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Great question! for the code, and pictures, it makes the problem a lot easier to understand as well as making it easier to quickly iterate on possible solutions.
The problem here is essentially a matplotlib one. Cartopy calls ax.set_aspect('equal') as this is part of the the Cartesian units of a projection's definition.
code :
``````def resize_colobar(event):
# Tell matplotlib to re-draw everything, so that we can get
# the correct location from get_position.
plt.draw()

posn = ax.get_position()
colorbar_ax.set_position([posn.x0 + posn.width + 0.01, posn.y0,
0.04, axpos.height])

fig.canvas.mpl_connect('resize_event', resize_colobar)
``````
``````import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import os
from netCDF4 import Dataset as netcdf_dataset
from cartopy import config

fname = os.path.join(config["repo_data_dir"],
)
dataset = netcdf_dataset(fname)
sst = dataset.variables['sst'][0, :, :]
lats = dataset.variables['lat'][:]
lons = dataset.variables['lon'][:]

fig, ax = plt.subplots(1, 1, figsize=(10,5),
subplot_kw={'projection': ccrs.PlateCarree()})

# Add the colorbar axes anywhere in the figure. Its position will be
# re-calculated at each figure resize.
cbar_ax = fig.add_axes([0, 0, 0.1, 0.1])

sst_contour = ax.contourf(lons, lats, sst, 60, transform=ccrs.PlateCarree())

def resize_colobar(event):
plt.draw()

posn = ax.get_position()
cbar_ax.set_position([posn.x0 + posn.width + 0.01, posn.y0,
0.04, posn.height])

fig.canvas.mpl_connect('resize_event', resize_colobar)

ax.coastlines()

plt.colorbar(sst_contour, cax=cbar_ax)

ax.gridlines()
ax.set_extent([-20, 60, 33, 63])

plt.show()
`````` ## Cartopy coastlines hidden by inset_axes use of Axes.pie

By : Krishna Sandeep
Date : March 29 2020, 07:55 AM
To fix this issue The problem is that each axes either lies on top or below another axes. So changing the zorder of artists within axes, does not help here. In principle, one could set the zorder of the axes themselves, putting the inset axes behind the main axes.
code :
``````ax_sub.set_zorder(axis_main.get_zorder()-1)
``````
``````ax_main.background_patch.set_visible(False)
``````
``````import cartopy.crs as ccrs
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.inset_locator import inset_axes

def plot_pie_inset(dataframe_pie,ilat_pie,ilon_pie,axis_main,width_local,alpha_local):
ax_sub= inset_axes(axis_main, width=width_local, height=width_local, loc=3,
bbox_to_anchor=(ilat_pie, ilon_pie),
bbox_transform=axis_main.transAxes,
wedges,texts= ax_sub.pie(dataframe_pie,colors=colors_dual)
for w in wedges:
w.set_linewidth(0.02)
w.set_alpha(alpha_local)
w.set_zorder(1)
plt.axis('equal')
# Put insets behind main axes
ax_sub.set_zorder(axis_main.get_zorder()-1)

colors_dual=['RosyBrown','LightBlue']
lat_list= np.arange(0.2,0.7,0.05)

fig= plt.figure()
ax_main= plt.subplot(1,1,1,projection=ccrs.PlateCarree())
ax_main.coastlines()

# set background patch invisible, such that axes becomes transparent
# since the GeoAxes from cartopy uses a different patch as background
# the following does not work
# ax_main.patch.set_visible(False)
# so we need to set the GeoAxes' background_patch invisible
ax_main.background_patch.set_visible(False)

for ilat in np.arange(len(lat_list)):
plot_pie_inset([75,25],lat_list[ilat],0.72,ax_main,0.2,0.9)

plt.show()
`````` 