【发布时间】:2018-05-01 15:20:50
【问题描述】:
我正在编写一个飞镖机器人。它是计算机器人撞击板的位置,现在我想使用 matplotlib 将其可视化。
我有什么: 使用带有轴和东西的常规极坐标投影显示机器人击中棋盘的位置。
我需要什么: 将飞镖设置为背景并在顶部绘制 X&Y(或分别为 theta 和 r)。
我尝试了什么: 将我的代码与接受的答案一起加入:Plot polar plot on top of image?
这就是我的代码现在的样子:
import numpy as np
from matplotlib import pyplot as plt
# throw three darts:
rad = np.asarray([10000, 11000, 9400]) # consider these as distances from bull's eye in 10*µm
azi = np.asarray([352, 0, 10]) # in degrees
azi = np.deg2rad(azi) # conversion into radians
fig = plt.gcf()
axes_coords = [0, 0, 1, 1] # plotting full width and height
ax_polar = fig.add_axes(axes_coords, projection='polar')
ax_polar.patch.set_alpha(0)
ax_polar.scatter(azi, rad)
ax_polar.set_ylim(0, 17000)
ax_polar.set_xlim(0, 2*np.pi)
ax_polar.set_theta_offset(0.5*np.pi) # 0° should be on top, not right
ax_polar.set_theta_direction(direction=-1) # clockwise
plt.show()
上面的代码工作正常。如果你运行它,你会看到机器人击中了靠近靶心正上方的 T20 场。
现在如果我想添加图片,我在plt.show()之前插入以下代码
pic = plt.imread('Board_cd.png')
ax_image = fig.add_axes(axes_coords)
ax_image.imshow(pic, alpha=.5)
ax_image.axis('off') # don't show the axes ticks/lines/etc. associated with the image
我做错了什么?
【问题讨论】:
-
这里不仔细看代码,我好像和How to add Roulette Wheel background image to matplotlib Radar Chart差不多。
-
感谢您的建议!对我来说不幸的是,您发布的问题的解决方案是通过 matplot 本身重新创建背景,这对我的情况来说几乎是不可能的......
-
我想如果你说你出于某种原因不想这样做也没关系;但肯定有可能。
-
好吧,总是首选没有图像的解决方案。也许我会更深入地研究这个,但目前我认为我无法完成这项任务。但你是对的 - 我应该记住它!
标签: python matplotlib projection