How to plot two 3D plots of matrices on the same figure with same scale in Python -


i have 2 matrices , have corresponding 2 3d plots on 2 subplots on same figure, same z axis.

this code far:

import numpy np import matplotlib.pyplot plt mpl_toolkits.mplot3d.axes3d import axes3d  def myplot(matrix1, matrix2):     mymin = np.min(np.array([np.min(matrix1), np.min(matrix2)]))     mymax = np.max(np.array([np.max(matrix1), np.max(matrix2)]))      xsize, ysize = matrix1.shape     x = np.arange(0, ysize, 1)     y = np.arange(0, xsize, 1)      xs, ys = np.meshgrid(x, y)     z1 = matrix1     z2 = matrix2      fig, (ax1, ax2) = plt.subplots(1, 2)     ax1 = axes3d(fig)     ax1.plot_surface(xs, ys, z1, rstride=1, cstride=1)     ax2 = axes3d(fig)     ax2.plot_surface(xs, ys, z2, rstride=1, cstride=1)     plt.tight_layout     plt.show()  mat1 = np.random.random(size = (10, 10)) mat2 = np.random.random(size = (10, 10))  myplot(mat1, mat2) 
  • why see 1 3d plot?
  • how can have same z axis in both plots?

i think need generate sub plots

see plot below (i've changed colouring too)

def myplot(matrix1, matrix2):     mymin = np.min(np.array([np.min(matrix1), np.min(matrix2)]))     mymax = np.max(np.array([np.max(matrix1), np.max(matrix2)]))      xsize, ysize = matrix1.shape     x = np.arange(0, ysize, 1)     y = np.arange(0, xsize, 1)      xs, ys = np.meshgrid(x, y)     z1 = matrix1     z2 = matrix2     fig=plt.figure()     ax1 = fig.add_subplot(2, 1, 1, projection='3d')     ax1.plot_surface(xs, ys, z1,color="blue",alpha=0.5,rstride=1, cstride=1)     ax2 = fig.add_subplot(2, 1, 2, projection='3d')     ax2.plot_surface(xs, ys, z2,color="green",alpha=0.5, rstride=1, cstride=1)     plt.tight_layout     plt.show()  mat1 = np.random.random(size = (10, 10)) mat2 = np.random.random(size = (10, 10))  myplot(mat1, mat2) 

enter image description here

edit: impose mymin , mymax limits of 2 z axes, use

ax1.set_zlim(mymin, mymax) ax2.set_zlim(mymin, mymax) 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -