Use numpy, matplotlib to view the effect of the curve

When designing parameters, you need to check the effect of the curve. At this time, you can use some online graphing websites to generate function graphs

Another simple solution is to use python's matplotlib tool to quickly achieve the goal

python install matplotlib library

python -m pip install -U matplotlib

Example:y=2^{x}

When x ranges from 0 to 10, I hope to see the curve of y

import numpy as np
import matplotlib.pyplot as plt
x=np.arange(0,10,0.1)
plt.plot(x,np.exp2(x))
plt.show()

curve effect

 It can be seen that as x gradually increases, the slope of y value becomes steeper and steeper, which is suitable for the calculation of height fog in graphics rendering

Example:y=x^{n}

When x ranges from 0 to 1, you want to see the change of y corresponding to different parameters n, then you can

import numpy as np
import matplotlib.pyplot as plt
x=np.arange(0,1,0.02)
for i in range(1,100,5):
	plt.plot(x,np.power(x,i))
plt.show()

curve effect

It can be seen intuitively that when n tends to infinity, the image is closer to a right angle, and this formula is suitable for edge sharpening

Example:\left\{\begin{matrix} x=z*sin(10*z)\\ y=z*cos(10*z)\\ z\in [0,10] \end{matrix}\right.

Three-dimensional image when the z value ranges from 0 to 10

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
fig=plt.figure()
ax=fig.add_subplot(projection='3d')
z=np.arange(0,10,0.01)
x=z*np.sin(10*z)
y=z*np.cos(10*z)
ax.plot3D(x,y,z)
plt.show()

generate image

Guess you like

Origin blog.csdn.net/tangyin025/article/details/128394917