0

I have a function defined in spherical coordinates for a constant radius. ( i.e. a 2D array )

omega1, dx = np.linspace(0, np.pi, 100, retstep=True)
psi1, dpsi = np.linspace(0, 2 * np.pi, 100, retstep=True)

omega, psi = np.meshgrid(omega1, psi1)

torus = PHI(21.5, omega, psi)

My aim is to plot this correctly on a sphere. I thought of using plotly but because of my computer being too new or because of an internal problem, I can't and I have the following error

ERROR:root:Cannot create GLX context. Aborting.

Anyway, I settled on Cartopy library following this exemple : Plotting cylindrical map data over a 3D sphere in Python.

Here my code :

plt.figure(figsize=(3, 3))

ax = plt.axes(projection=ccrs.Orthographic(0, 0))
ax.gridlines(crs=ccrs.PlateCarree(),linestyle='dotted',draw_labels=True,
                      linewidth=2, color='gray', alpha=0.5)
gl=ax.imshow(torus, origin="upper", extent=(-180, 180, -90, 90),
              transform=ccrs.PlateCarree())
gl.xlocator = mticker.FixedLocator([-180, -45, 0, 45, 180])
gl.xformatter = LONGITUDE_FORMATTER
gl.yformatter = LATITUDE_FORMATTER
gl.xlabel_style = {'size': 15, 'color': 'gray'}
gl.xlabel_style = {'color': 'red', 'weight': 'bold'}

plt.show()

I get this image.

enter image description here

However, I have several questions that I can't solve even after reading the Cartopy instructions. Can you please clarify this for me. First , how can I be sure that the latitudes and longitudes of my image correspond to those desired? I suppose it's in the extent parameter but if I follow my linespace and put :

extent=(0, 360, 0, 180)

I don't get any more. My second question is how to check which labels are indicated. For example on my image the latitudes are shown, but how do I get the longitudes for instance ? I find it hard to understand how the legends of this type of plot work.

Of course if you have other libraries to get this kind of thing I'm interested.

dodo27
  • 11
  • 2

0 Answers0