matplotlib 库常用用法--散点图绘制
# 散点图绘制
# 1、代码示例
import numpy as np
import matplotlib.pyplot as plt
# Fixing random state for reproducibility
np.random.seed(19680801)
N = 50
x = np.random.rand(N)
y = np.random.rand(N)
colors = np.random.rand(N)
area = (30 * np.random.rand(N))**2 # 0 to 15 point radii
plt.scatter(x, y, s=area, c=colors, alpha=0.5)
plt.show()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 2、自写代码
ax.scatter(noisy_sample_pd1, noisy_sample_pd2, c='lightcoral', marker='+', alpha=0.6, label="Noisy Sample")
ax.scatter(clean_sample_pd1, clean_sample_pd2, c='darkcyan', marker='x', alpha=0.6, label="Clean Sample")
# concat two image
def mix_img(path1, path2, save_path):
img1 = cv2.imread(path1)
img2 = cv2.imread(path2)
image_concat = np.concatenate([img1, img2], axis=1)
cv2.imwrite(save_path, img=image_concat)
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
#
# 3、参数解析
c
参数如下图(参考链接 (opens new window))m
参数如下图(参考链接 (opens new window))
# 拼图
image_concat1 = np.concatenate([img, mask], axis=1)
image_concat2 = np.concatenate([img, color_mask], axis=1)
mmcv.imwrite(image_concat1, 'test1.png')
mmcv.imwrite(image_concat2, 'test2.png')
plt.subplot(1, 3, 1)
plt.imshow(img)
plt.title("img", fontsize=8)
plt.subplot(1, 3, 2)
plt.imshow(mask, cmap ='gray')
plt.title(f"img_noise_erode_", fontsize=8)
plt.subplot(1, 3, 3)
plt.imshow(color_mask)
plt.title(f"img_noise_dilate_", fontsize=8)
plt.savefig('test.png')
plt.show()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 参考资料
https://matplotlib.org/stable/api/index.html
https://matplotlib.org/2.0.2/examples/color/named_colors.html
https://matplotlib.org/stable/api/markers_api.html#module-matplotlib.markers
https://matplotlib.org/stable/gallery/shapes_and_collections/scatter.html#sphx-glr-gallery-shapes-and-collections-scatter-py
https://matplotlib.org/stable/tutorials/introductory/sample_plots.html#sphx-glr-tutorials-introductory-sample-plots-py
参考资料
- https://flashgene.com/archives/163100.html
上次更新: 2021/09/26, 00:09:41
- 02
- README 美化05-20
- 03
- 常见 Tricks 代码片段05-12