I have three lists xs, ys, zs of data points in Python and I am trying to create a 3d plot with matplotlib
using the scatter3d
method.
import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111, projection='3d') plt.xlim(290) plt.ylim(301) ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') ax.scatter(xs, ys, zs) plt.savefig('dateiname.png') plt.close()
The plt.xlim()
and plt.ylim()
work fine, but I don't find a function to set the borders in z-direction. How can I do so?
Create u, v, x, y and z data points using numpy. Plot a 3D wireframe. Set the title of the plot. Save the current figure using savefig() method.
Surface plots are created by using ax. plot_surface() function. where X and Y are 2D arrays of points of x and y while Z is a 2D array of heights.
Simply use the set_zlim
function of the axes
object (like you already did with set_zlabel
, which also isn't available as plt.zlabel
):
import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import numpy as np xs = np.random.random(10) ys = np.random.random(10) zs = np.random.random(10) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') ax.scatter(xs, ys, zs) ax.set_zlim(-10,10)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With