It is quite easy to make a 3d stem plot with stem3 command as documented in http://www.mathworks.com/help/techdoc/ref/stem3.html I wonder if there is a similar command in matplotlib? I checked the online document for the latest version, but could not find one. Can anyone give some suggestions?
I'm unaware of any direct equivalent of stem3
in matplotlib. However, it isn't hard to draw such figures (at least in its basic form) using Line3Ds:
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d.art3d as art3d
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d')
N = 100
theta = np.linspace(0, 2*np.pi, N, endpoint=False)
x = np.cos(theta)
y = np.sin(theta)
z = range(N)
for xi, yi, zi in zip(x, y, z):
line=art3d.Line3D(*zip((xi, yi, 0), (xi, yi, zi)), marker='o', markevery=(1, 1))
ax.add_line(line)
ax.set_xlim3d(-1, 1)
ax.set_ylim3d(-1, 1)
ax.set_zlim3d(0, N)
plt.show()
As unutbu's, just with a conventional plot:
In [20]: from mpl_toolkits.mplot3d import Axes3D
In [21]: fig = figure()
In [22]: ax = fig.add_subplot(111, projection='3d')
In [23]: x = [2,4,1,3]
In [24]: y = [3,5,6,7]
In [25]: z = [4,5,6,7]
In [26]: for xx,yy,zz in zip(x,y,z): plot([xx,xx],[yy,yy],[0,zz], '-')
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