If you read the tutorials on matplot, you can find many nice examples of 3d drawing such as saddle type and trigonometric function composition. In practice, for example, you want to plot the number of customers, sales (depending on the number of customers), and time (independent variable) to show when the number of customers and sales exceeded or fell below the threshold. There are times when Z does not depend on X or Y and you simply want to stretch y = f (x) in the Z direction for display. I thought it would be easy, but I was worried because there were few examples because it was too plain in the picture, so I would like to make a note of it. I have a very short history of programming, so if you have any suggestions for improvement, please do not hesitate to contact me.
python
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
x = [1,2,3,4,5]
y = [2,4,6,8,10]
z = np.linspace(0,100,11)
Y,Z = np.meshgrid(y,z)
X = np.array([x]*Y.shape[0])
fig = plt.figure()
ax = Axes3D(fig)
ax.set_xlabel("X")
ax.set_ylabel("Y")
ax.set_zlabel("Z")
ax.plot_surface(X,Y,Z,alpha = 0.3)
python
x = 2
y = np.linspace(0,100,11)
z = np.linspace(0,100,11)
Y,Z = np.meshgrid(y,z)
X = np.array([x]*Y.shape[0])
fig = plt.figure()
ax = Axes3D(fig)
ax.set_xlabel("X")
ax.set_ylabel("Y")
ax.set_zlabel("Z")
ax.plot_surface(X,Y,Z,alpha=0.3)
After that, you can overlay the 3D scatter plot or draw the wire frame line from above. However, the 3D drawing on the display is hard to see from the side that can be seen, so I think it is better not to use it as much as possible.
Recommended Posts