用Pyplot绘制图像上的输入点
我想用Pyplot绘制图像,并在该图像上绘制一个点。 该点来自Pyplot中的输入字段。在这里,我有一个代码,您可以在其中提出点,但是在按Enter或搜索按钮后,它不会绘制重点。这是我的代码:
import cv2
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import TextBox
def imshow_rgb(img_bgr):
img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
plt.imshow(img_rgb)
ims = cv2.imread('plattegrondtekening.png', 1)
fig = plt.imshow(np.flipud(ims), cmap='gray', origin='lower')
plt.subplots_adjust(bottom=0.2)
initial_text = ""
x,y=[500,500]
def submit(text):
x,y = list(map(int,text.split(",")))
print(x,y)
plt.plot(x, y, "ro")
plt.show()
axbox = plt.axes([0.1, 0.05, 0.8, 0.075])
text_box = TextBox(axbox, 'search', initial=initial_text)
text_box.on_submit(submit)
plt.show()
但是我希望它在x = 900和y = 800上显示一个点,当我在输入框中输入900,800时。
I want to plot an image with pyplot and on top of that image a point.
That point is from an input field in the pyplot. Here I have a piece of code, where you can put a point in, but after pressing enter, or search button it won't plot the point. Here is my code:
import cv2
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import TextBox
def imshow_rgb(img_bgr):
img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
plt.imshow(img_rgb)
ims = cv2.imread('plattegrondtekening.png', 1)
fig = plt.imshow(np.flipud(ims), cmap='gray', origin='lower')
plt.subplots_adjust(bottom=0.2)
initial_text = ""
x,y=[500,500]
def submit(text):
x,y = list(map(int,text.split(",")))
print(x,y)
plt.plot(x, y, "ro")
plt.show()
axbox = plt.axes([0.1, 0.05, 0.8, 0.075])
text_box = TextBox(axbox, 'search', initial=initial_text)
text_box.on_submit(submit)
plt.show()
image plot with input field below, this is the output of the code above
But I want that it shows a point on x=900 and y=800, when I enter 900,800 in the input box.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们必须首先使用
plt.sca(ax)
首先选择活动轴,并且为了刷新画布,我们可以使用fig.canvas.draw()
and code>和图。 canvas.flush_events()
。替换
fig = plt.imshow(np.flipud(ims),cmap ='灰色',oneration ='lower')
with:替换
plt.plt.plot(x,x,y,x,y,y,y,y,y,y,y,y,y,y of “ ro”)
和plt.show()
with:code示例:
We have to select the active axes first using
plt.sca(ax)
and for refreshing the canvas we may usefig.canvas.draw()
andfig.canvas.flush_events()
.Replace
fig = plt.imshow(np.flipud(ims), cmap='gray', origin='lower')
with:Replace
plt.plot(x, y, "ro")
andplt.show()
with:Code sample: