Questions tagged [mplot3d]

a 3D plotting toolkit which ships with the matplotlib Python plotting library.

The mplot3d toolkit adds simple 3D plotting capabilities to the plotting library.

Resources

391 questions
187
votes
5 answers

how to set "camera position" for 3d plots using python/matplotlib?

I'm learning how to use mplot3d to produce nice plots of 3d data and I'm pretty happy so far. What I am trying to do at the moment is a little animation of a rotating surface. For that purpose, I need to set a camera position for the 3D projection.…
Andreas Bleuler
  • 1,991
  • 2
  • 12
  • 6
56
votes
3 answers

How to display a 3D plot of a 3D array isosurface with mplot3D or similar

I have a 3-dimensional numpy array. I'd like to display (in matplotlib) a nice 3D plot of an isosurface of this array (or more strictly, display an isosurface of the 3D scalar field defined by interpolating between the sample points). matplotlib's…
timday
  • 24,582
  • 12
  • 83
  • 135
54
votes
2 answers

3d axes ticks, labels, and LaTeX

I am running this sample script, with the following modifications: import matplotlib as mpl from mpl_toolkits.mplot3d import Axes3D import numpy as np import matplotlib.pyplot as plt mpl.rcParams['legend.fontsize'] = 10 fig = plt.figure() ax =…
Forklift17
  • 2,245
  • 3
  • 20
  • 32
36
votes
7 answers

How to increase the size of an axis (stretch) in a 3D Plot

I have this so far: x,y,z = data.nonzero() fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.scatter(x, y, z, zdir='z', c= 'red') plt.savefig("plot.png") Which creates: What I'd like to do is stretch this out to make the Z axis…
Greg
  • 45,306
  • 89
  • 231
  • 297
34
votes
5 answers

Setting aspect ratio of 3D plot

I am trying to plot a 3D image of the seafloor from the data of a sonar run over a 500m by 40m portion of the seafloor. I am using matplotlib/mplot3d with Axes3D and I want to be able to change the aspect ratio of the axes so that the x & y axis are…
Blair
  • 15,356
  • 7
  • 46
  • 56
30
votes
2 answers

Surface and 3d contour in matplotlib

I would like to plot a surface with a colormap, wireframe and contours using matplotlib. Something like this: Notice that I am not asking about the contours that lie in the plane parallel to xy but the ones that are 3D and white in the image. If I…
nicoguaro
  • 3,629
  • 1
  • 32
  • 57
29
votes
3 answers

How do I set a maximum value for the z-axis?

I am trying to make a 3-dimensional surface plot for the expression: z = y^2/x, for x in the interval [-2,2] and y in the interval [-1.4,1.4]. I also want the z-values to range from -4 to 4. The problem is that when I'm viewing the finished…
user605243
  • 291
  • 1
  • 3
  • 3
28
votes
2 answers

How to scale 3d axes

I can't seem to find documentation regarding the ability to scale axes in a 3d image using matplotlib. For example, I have the image: And the axes have different scales. I would like them to be uniform.
Chris
  • 9,603
  • 15
  • 46
  • 67
27
votes
2 answers

Plotting points on the surface of a sphere

I'm trying to generate a plot of a sphere, with some points plotted on the surface of the sphere. (Specifically the points are the Lebedev quadrature points) I want my plot to look similar to this one that I found online: I proceed by plotting a…
O Smith
  • 375
  • 1
  • 3
  • 11
25
votes
1 answer

I want to use matplotlib to make a 3d plot given a z function

I have a z function that accepts x and y parameters and returns a z output. I want to plot this in 3d and set the scales. How can I do this easily? I've spent way too much time looking through the documentation and not once do I see a way to do…
WhatsInAName
  • 969
  • 2
  • 9
  • 12
23
votes
1 answer

How to project filled contour onto a 3d surface plot

I'm simply trying to plot a surface and its contour in 3D, exactly as in this example. This is the code I'm using to do it: import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import axes3d from matplotlib import cm import numpy def…
pceccon
  • 9,379
  • 26
  • 82
  • 158
23
votes
4 answers

Plotting a 2d Array with mplot3d

I have a 2D numpy array and I want to plot it in 3D. I heard about mplot3d but I cant get to work properly Here's an example of what I want to do. I have an array with the dimensions (256,1024). It should plot a 3D graph where the x axis is from 0…
Fourier
  • 435
  • 2
  • 5
  • 10
22
votes
3 answers

How do I crop an Axes3D plot with square aspect ratio?

Here's a barebones example: import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D fig = plt.figure() f = fig.add_subplot(2, 1, 1, projection='3d') t = fig.add_subplot(2, 1, 2, projection='3d') # axes for d in {f, t}: …
endolith
  • 25,479
  • 34
  • 128
  • 192
21
votes
1 answer

Connecting two points in a 3D scatter plot in Python and matplotlib

In the code below, how do I create lines connecting each pair of scatter plots (i.e. linking the green circle to the yellow arrowhead) created by the two lines of code towards the end just before the .show() instruction? import…
Zambi
  • 363
  • 1
  • 3
  • 9
20
votes
5 answers

PyPlot legend: 'Poly3DCollection' object has no attribute '_edgecolors2d'

The following code snippet works fine until I uncomment the plt.legend() line: import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D x = np.linspace(-1, 1) y = np.linspace(-1, 1) X, Y = np.meshgrid(x, y) Z =…
Jacob Stern
  • 3,758
  • 3
  • 32
  • 54
1
2 3
26 27