Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set zlim in matplotlib scatter3d

Tags:

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?

like image 642
Jann Avatar asked May 30 '16 09:05

Jann


People also ask

How do you save a 3D plot in Python?

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.

How do you plot a surface in Python?

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.


1 Answers

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) 
like image 60
Bart Avatar answered Sep 20 '22 19:09

Bart