1 回答
TA贡献1719条经验 获得超6个赞
我已经用 numpy 做到了这一点。是的,它很丑,但它确实有效。
import numpy as np
import matplotlib.pyplot as plt
data = [[[0, 0], [300, 400]],
[[10, 30], [50, 35]],
[[143, 12], [244, 113]]] # I modified this for better visualization
values = [1, 3, 4] # if your rectangles have values
data_range = [1000, 1000] # assumed max data range is (0, 999)
areas = np.zeros(data_range) # initialize empty area
for i, points in enumerate(data):
areas[points[0][1]:points[1][1]+1, points[0][0]:points[1][0]+1] += values[i] # I agree that it's too ugly
# I use `+1` to take these points too
# change `values[i]` to `1` if it just needs counting
# visualize result
plt.imshow(areas)
plt.colorbar()
plt.show()
结果:
添加回答
举报