首页 > 解决方案 > 在单个网格中重叠 pyplot.imshow() 图

问题描述

我想绘制这些数字。对于第一张图:

图1.png

对于代码片段:

import matplotlib.pyplot as plt
row = 30
col = row
areas_pher = [[-0.01 for i in range(col)] for j in range(row)] 

for i in range(1, row-1):
    for j in range(1, col-1):
         areas_pher[i][j] = 0
max_pher = 20
for pher in range(1, col-1):
    areas_pher[15][pher] = max_pher * pher/max_pher
plt.imshow(areas_pher, cmap="Blues_r", vmin=0, vmax=max_pher)

第二个图:

图2.png

对于代码片段:

import matplotlib.pyplot as plt
import numpy as np

areas_ant = [[6 for i in range(col)] for j in range(row)]
prob_ant = 0.05    

for i in range(1, row-1):
    for j in range(1, col-1):
        rand = np.random.rand()
        if rand < prob_ant:
            areas_ant[i][j] = 5
plt.imshow(areas_ant, cmap="Blues")

我的问题是,让它的数字重叠的最佳方法是什么,如下图所示?

重叠图形插图.png

标签: pythonmatplotlibimshow

解决方案


推荐阅读