I am trying to plot several 2D panels in order to form three boxes using Python but am having some trouble. What I have right now uses Matplotlib, but I'm open to using something else if it's easier.
Basically this is a MWE of what I got:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
L = 400
dx=2*4
dz=1*4
# create the figure
fig, axes = plt.subplots(ncols=1, nrows=1, figsize=(16, 8), subplot_kw=dict(projection='3d', aspect="equal"))
ax=axes
for i in range(3):
x, y, z = np.arange(dx/2, L, dx)+i*5*L/4, np.arange(dx/2, L, dx), np.arange(-240, dz, dz)
xx, yy = np.meshgrid(x, y)
A=np.random.rand(*xx.shape)
#----
# Plot surface
X = xx
Y = yy
Z = np.zeros_like(xx)
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors=plt.cm.viridis(A), shade=False)
#----
#----
# Plot x-z cross-section
xx, zz = np.meshgrid(x, z)
Y=np.zeros_like(xx)
X=xx
Z=zz
B=np.random.rand(*xx.shape)*2
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors=plt.cm.viridis(B), shade=False)
#----
#----
# Plot x-z cross-section
yy, zz = np.meshgrid(y, z)
X=np.zeros_like(xx)+xx.max()
Y=yy
Z=zz
B=np.random.rand(*xx.shape)/2
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors=plt.cm.viridis(B), shade=False)
#----
#ax.set_axis_off()
# make the panes transparent
ax.xaxis.set_pane_color((1.0, 1.0, 1.0, 0.0))
ax.yaxis.set_pane_color((1.0, 1.0, 1.0, 0.0))
ax.zaxis.set_pane_color((1.0, 1.0, 1.0, 0.0))
# make the grid lines transparent
ax.xaxis._axinfo["grid"]['color'] = (1,1,1,0)
ax.yaxis._axinfo["grid"]['color'] = (1,1,1,0)
ax.zaxis._axinfo["grid"]['color'] = (1,1,1,0)
This code is based on this answer and it produces this:
Two things are wrong with this picture:
- the aspect ratio is off
- the boxes are always too small compared to the size of the picture
I think I can somewhat take care of the aspect ratio problem with some hacks, even though it would be nice to deal with it in a proper way. However, I have tried like crazy to zoom in the picture without success.
Again, I'm willing to use something other than pyplot, although, since I'm planing on using xarray, it would be nice to have something that blends in nicely with it.
