代码部分:
import matplotlib.pyplotas plt
import numpyas np
import pandasas pd
# 绘制x、y轴的次刻度,导入MultipleLocator
from matplotlib.tickerimport MultipleLocator
from matplotlibimport cm
from matplotlib.colorsimport ListedColormap, LinearSegmentedColormap
# 设置字体和颜色
plt.rcParams['font.size'] =15
plt.rcParams['font.family'] ='serif'
N =100
# 设置颜色
top = cm.get_cmap('Oranges_r', 128)
bottom = cm.get_cmap('Blues', 128)
newcolors = np.vstack((top(np.linspace(0, 1, 128)), bottom(np.linspace(0, 1, 128))))
orange_blue = ListedColormap(newcolors, name='OrangeBlue')
np.random.seed(100)
# 生成X、Y随机数
randx = np.random.random(N) *100
randy = np.random.random(N) *100
size = np.random.randint(50, 200, size=N)
# 设置生成图片的大小
plt.figure(figsize=(15, 10))
# c = size控制散点图气泡大小,cmap = orange_blue,设置颜色,如果cmap设置其他的颜色,可以查询这个网站:https://matplotlib.org/2.0.2/users/colormaps.html
plt.scatter(randx, randy, s=size, c=size, alpha=0.8, cmap=orange_blue)
plt.axis('equal')
# 设置坐标轴次刻度
ax = plt.gca()
ax.xaxis.set_minor_locator(MultipleLocator(10))
ax.yaxis.set_minor_locator(MultipleLocator(10))
plt.xlabel('randx')
plt.ylabel('randy')
plt.colorbar(label='circle size')
plt.tight_layout()
plt.show()

网友评论