There was a request to draw a 3D graph in a nice way, and when I looked up "How can I write it in a nice way ...", it came out that it could be drawn with Python's matplotlib. So, this time I will write from installing Python to drawing a 3D graph.
There are many articles about installation, so I will omit it. I entered it with reference to the following.
Installing python in windows environment
However, because Windows 10 is bad or my PC is bad, Python Path does not pass in the environment variable, so add the following path.
C:\\Python27
It became super easy before I knew it! Just go to the following site, download "get-pip.py" and execute it.
Start the command prompt, move to the location where you downloaded get-pip.py, and execute the following command to enter pip.
python get-pip.py
Install numpy for data organization and matplotlib for drawing.
python -m pip install numpy
python -m pip install matplotlib
Now you are ready.
For the drawing program, I referred to the following site. Draw 3D graph with matplotlib
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
#Range and spacing settings
x = np.arange(-5, 5, 0.25)
y = np.arange(-5, 5, 0.25)
#Mesh drawing settings
X, Y = np.meshgrid(x, y)
#Calculation
Z = np.sin(X)+ np.cos(Y)
fig = plt.figure()
ax = Axes3D(fig)
#plot
ax.plot_wireframe(X,Y,Z)
plt.show()
If I can do it so far, I think I should just learn how to handle numpy ...? I managed to figure out how to draw in 3D, so I'm struggling to plot the results processed by OpenCV.
Recommended Posts