当前位置: 移动技术网 > IT编程>脚本编程>Python > matplotlib 显示两张图片,折线图 和 scipy

matplotlib 显示两张图片,折线图 和 scipy

2019年02月25日  | 移动技术网IT编程  | 我要评论

cctv7乡土全集,防御狙击手,刚毅不屈造句

显示两张图片的代码:

import numpy as np
from scipy.misc import imread, imsave, imresize
import matplotlib.pyplot as plt


img = imread('cat.jpg')
print(img.dtype, img.shape)  # uint8 (500, 500, 3)

img_tinted = img * [1, 0.1, 0.5]  # rgb
img_tinted = imresize(img_tinted, (300, 600))
imsave('cat_tinted.jpg', img_tinted)

plt.subplot(1, 2, 1)
plt.imshow(img)

plt.subplot(1, 2, 2)
plt.imshow(img_tinted)

plt.show()

显示结果:


显示四张图片的代码:

x = np.arange(0, 2 * np.pi, 0.1)
y_sin = np.sin(x)
y_cos = np.cos(x)

plt.subplot(2, 2, 1)
plt.plot(x, y_sin)
plt.plot(x, y_cos)
plt.xlabel('x axis label')
plt.ylabel('y axis label')
plt.title('sine and cosine')
plt.legend(['sine', 'cosine'])

plt.subplot(2, 2, 2)
plt.plot(x, y_sin)
plt.title('sine')
plt.legend(['this is sine'])

# img = imread('cat.jpg')
plt.subplot(2, 2, 3)
plt.imshow(img)

plt.subplot(2, 2, 4)
plt.imshow(np.uint8(img_tinted))

plt.show()

显示结果:


计算任意两点间的欧氏距离

from scipy.spatial.distance import pdist, squareform
x= np.array([[0, 1], [1, 0], [2, 0]])
d= squareform(pdist(x, 'euclidean'))
print(d)

[[0. 1.41421356 2.23606798]
[1.41421356 0. 1. ]
[2.23606798 1. 0. ]]

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网