今天,我们来把教程里剩下的东西了解完
首先,我们来了解一下Subplots
我们可以使用Subplots中的一些函数来绘制一些东西,以下是例子
import numpy as np
import matplotlib.pyplot as plt
x =np.arange(0, 3 * np.pi , 0.1)
y_sin = np.sin(x)
y_cos = np.cos(x)
plt.subplot(2,1,1)
plt.plot(x, y_sin)
plt.title('Sine')
plt.subplot(2, 1, 2)
plt.plot(x, y_cos)
plt.title('Cosine')
plt.show()
结果如下图所示
接下了我们来看最后一点Images
你可以使用imshow的方法来显示图片,下面是个例子
import numpy as np
from scipy.misc import imread, imresize
import matplotlib.pyplot as plt
img = imread('C:/Users/Administrator/Pictures/1.jpg')
img_tinted = img * [1, 0.95, 0.9]
# Show the original image
plt.subplot(1, 2, 1)
plt.imshow(img)
# Show the tinted image
plt.subplot(1, 2, 2)
# A slight gotcha with imshow is that it might give strange results
# if presented with data that is not uint8. To work around this, we
# explicitly cast the image to uint8 before displaying it.
plt.imshow(np.uint8(img_tinted))
plt.show()
显示结果如下图所示(随便找了个图片)
还是会有以前提到的那个问题,就是scipy的版本问题,
现在版本是1.2.0, imread()改成了imageio.imread()
虽然报错了,但是结果还是显示出来了,奇怪
心得:通过这2个星期的了解,也算对python以及其的库有了一些的认识,能正常使用,但还需深入了解。
这个Python的初级了解就到这里结束了