【发布时间】:2021-11-07 16:26:08
【问题描述】:
我正在尝试绘制一个网格,其中每个框中的箭头居中,并在特定单元格中着色。这就是我到目前为止所拥有的。可悲的是,箭头没有居中,但我尽力了。
arrow_direction_per_cell = {(0, 0): 'RIGHT',(0, 1): 'DOWN',(0, 2): 'UP',(0, 3): 'LEFT',(0, 4): 'UP',
(1, 0): 'RIGHT',(1, 1): 'RIGHT',(1, 2): 'DOWN',(1, 3): 'LEFT', (1, 4): 'LEFT',(2, 0): 'RIGHT',(2, 1): 'RIGHT',
(2, 2): 'DOWN',(2, 3): 'LEFT',(2, 4): 'UP',(3, 0): 'LEFT',(3, 1): 'RIGHT',(3, 2): 'UP',(3, 3): 'LEFT',(3, 4): 'UP',
(4, 0): 'LEFT',(4, 1): 'DOWN', (4, 2): 'UP',(4, 3): 'UP', (4, 4): 'UP'}
direction_map = {'UP':(0,1),'DOWN':(0,-1),'RIGHT':(1,0),'LEFT':(-1,0)}
locations = arrow_direction_per_cell.keys()
fig, ax = plt.subplots()
plt.xlim(0, 5)
plt.ylim(5, 0)
plt.grid(True)
plt.xticks(np.arange(0, 6, 1.0))
plt.yticks(np.arange(0, 6, 1.0))
for location in locations:
arrow_direction = arrow_direction_per_cell[location]
x_pos,y_pos = (location[0]+.5),(location[1]+.5)
x_direct,y_direct = direction_map[arrow_direction]
ax.quiver(x_pos, y_pos, x_direct, y_direct,scale=30)
cells_to_be_orange = [(0,2),(2,4),(3,4)]
cells_to_be_blue = [(3,2)]
ax.quiver(x_pos, y_pos, x_direct, y_direct)
plt.show()
如何在“cells_to_be_orange”橙色和“cells_to_be_blue”蓝色的位置上着色,以及如何使箭头看起来更居中?
非常感谢,祝你有美好的一天。
【问题讨论】:
标签: python matplotlib data-visualization