I am plotting a set of 3D coordinates (x, y, z) using Axes3D, reads my code Import the NMP as import
import as mpl_toolkits.mplot3d from plpl as matplotlib.pyplot Axes3D x, y, z = data [:: 1,0], data [:: 1, 1], data [:: 1,2] fig = PLT.figer (figs = (10,10)) ax = fig. Ada_spelot (111, projection = '3d') ax.scatter (x, y, z, s = 0.1, c = z, cmap = 'hot', marker = '+') plt.show ()
I want all three axes to have the same scaling. Now, the problem is that there is a large aspect ratio of data, that is, the difference in the X and Y coordinates is about 10 times higher than the change in z coordination. If I
mi = np.min (data) ma = np.max (data) ax.set_xlim (mi, ma) ax.set_ylim (mi, ma) ax.set_zlim (mi) Put, ma)
This will result in equally enhanced axes but Jade will ruin a lot of space in the direction. How can I avoid this evenly and evenly extended axes?
So one question is that it is similar ... but I can not find it . So I guess what I understand is some code is attached to your problem (the thing that does not mine is mine, but that is from the other post I said) And, the result is:
import Np import matlotlib.pyplot as numpy plt as Axes3D data = np.random.rand (100,3) x, y, z = 10 * data [, 0], 20 * data from Mpl_toolkits.mplot3d [ Axis.x (figsize = (10,10)) ax = fig.add_subplot (111, projection = '3') ax.scatter (x, y, Z) # Fix Aspect Ratio max_range = np.array ([x .max () - x.min (), y.max () - y.min (), z.max () - z.min ( )]). Maximum () / 2.0 mean_x = x.mean () mean_y = y.mean () mean_z = z.mean () ax.set_xlim (mean_x - max_range, mean_x + max_range) ax.set_ylim (mean_y - max_range, mean_y + max_range) Ax.set_zlim (mean_z - max_range, mean_z + max_range) plt. Show ()
No comments:
Post a Comment