1.Python:matplotlib绘图时指定图像大小,放大图像
matplotlib绘图时是默认的大小,有时候默认的大小会感觉图片里的内容都被压缩了,解决方法如下。
先是原始代码:
|
1 2 3 4 5 6 7 |
|
关键的代码是plt.figure(figsize=(1,1)),生成的图片如下
修改代码,放大图片:
|
1 2 3 4 5 6 7 |
|
这时候横坐标和纵坐标都放大了10倍:
如果想要指定像素,可以这么做:
|
1 2 3 4 5 6 7 |
|
2.Python:matplotlib绘图-scatter 散点图
import matplotlib.pyplot as plt import numpy as np # unit area ellipse rx, ry = 3., 1. area = rx * ry * np.pi theta = np.arange(0, 2 * np.pi + 0.01, 0.1) verts = np.column_stack([rx / area * np.cos(theta), ry / area * np.sin(theta)]) x, y, s, c = np.random.rand(4, 30) s *= 10**2. fig, ax = plt.subplots() ax.scatter(x, y, s, c, marker=verts) plt.show()