2017-08-23 110 views
0

我繪製2D曲線以代號如何通過SciPy繪製3D曲線?

c = 11 
x = np.arange(0, 5, 0.1) 
y = np.exp(c)/x 
plt.plot(x,y) 

怎樣繪製一系列x,y曲線而z軸是c的?第一行改爲

c = np.arange(1, 70, 1) 

怎樣繪製沿z軸70條x,y曲線?

回答

2

你可以使用matplotlibs Axes3D,教程可以發現here

import numpy as np 
import matplotlib.pyplot as plt 
from mpl_toolkits.mplot3d import Axes3D 

c = np.arange(1, 10, 1) # made this 10 so that the graph is more readable 
x = np.arange(0, 5, 0.1) 

fig = plt.figure() 
ax = fig.add_subplot(111, projection='3d') 

for i in c: 
    y = np.exp(i)/x 
    ax.plot(x, y, i) 

    ax.set_xlabel("x") 
    ax.set_ylabel("y") 
    ax.set_zlabel("z") 

plt.show() 

這給圖:

enter image description here