I tried to create a surface plot with Python 3 and now I am wondering why it is transparent? Any ideas? I expected it to look like the plot I created with MATLAB using the same data set ETOPO1. A second question, changing the aspect ratio isn't possible with plot_surface,right?
Best, Martin
import numpy as np
from matplotlib import cm
import matplotlib.pyplot as plt
from matplotlib.colors import LightSource
ETOPO1 = np.flipud(ETOPO1)
lon = np.arange(30,60+1/60,1/60)
lat = np.arange(-20,20+1/60,1/60)
LON,LAT = np.meshgrid(lon,lat)
fig, ax2 = plt.subplots(subplot_kw={"projection": "3d"})
ls = LightSource(270,45)
rgb = ls.shade(ETOPO1,
cmap=cm.gist_earth,
vert_exag=0.1,
blend_mode='hsv')
ax2.plot_surface(LON,LAT,ETOPO1,
rstride=1, cstride=1,
linewidth=0,
facecolors=rgb,
antialiased=True,
shade=True)
ax2.view_init(60, 20-90)
ax2.tick_params(axis='both', labelsize=6)
ax2.grid(False)
plt.show()
Edit 1 Dec 2021
Here are a few related questions:
The code above needs 15 sec if I use rstride=5, cstride=5 but 318 sec = 5.3 min if I use the full resolution rstride=1, cstride=1. This is surprising as MATLAB needs 0.14 sec for the full resolution – why?
I tried to add contours on top of the surface using
v = np.array([500,1000,2000,3000]) ax2.contour(LON,LAT,ETOPO1+1, levels=v,linewidths=0.3, colors='r',linestyles='solid')
but, despite adding 1, 10, or 100 to ETOPO1, they are always hidden by the surface.
I tried to save the figure using ETOPO1, I
plt.savefig('etopo1_python.png',dpi=300)
but got an empty image in the PNG file. Any ideas?
Since
antialiased=True
causes transparency, the question arises, is it a bug?