Use matplotlib Videos in a plurality of curves of FIG.

Do data analysis, machine learning when there is convergence, accuracy analysis, often need some data graphically displayed in the form of curves, the following describes two ways to achieve this small problem, one is object-oriented object-oriented, and the other is based on the plt.

The following approach is object-oriented approach:

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0,2,100)
fig,ax = plt.subplots()
ax.plot(x,x,label='linear')
ax.plot(x,x**2,label='quadratic')
ax.plot(x,x**3,label='cubic')
ax.set_xlabel('x label')
ax.set_ylabel('y label')
ax.set_title('simple plot')
ax.legend()
plt.show()

将图形中的每个元素进行定义,然后组建成一个整体图像,是基于对象的。

The above pattern generated code as shown below:

 

 

Another completely plt given code as follows:

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0,2,100)

plt.plot(x,x,label='linear')
plt.plot(x,x**2,label='quadratic')
plt.plot(x,x**3,label='cubic')
plt.xlabel('x label')
plt.xlabel('y label')
plt.title('simple plot')
plt.legend()
plt.show()

Resulting in two ways is the same as FIG.

To why these code into object-oriented and based plt it, since each part is made to FIG matplotlib can be seen as a separate object, such as coordinate axes, the scale of coordinate axes, the coordinate axis name, title, and so this figure may be a good description of the problem below this figure, as it has been a part of each labeled out.

Published 36 original articles · won praise 11 · views 6523

Guess you like

Origin blog.csdn.net/t20134297/article/details/105018198