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

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

显示两张图片的代码:

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()

显示结果:

604263-20190224194430098-1072435947.jpg


显示四张图片的代码:

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()

显示结果:

604263-20190224194658072-1126574538.jpg


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

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. ]]

posted @ 2019-02-24 20:26 YangZhaonan 阅读(...) 评论(...) 编辑 收藏

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值