如何在matplotlib / Python中直接在散焦图上叠加jpg图像? [英] How do you directly overlay a scatter plot on top of a jpg image in matplotlib / Python?

查看:150
本文介绍了如何在matplotlib / Python中直接在散焦图上叠加jpg图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要快速绘制jpg帧作为跟踪算法的输出结果。与jpg帧的伴侣是包含简单(x,y)数据的文本文件,其定位正被跟踪的图像目标。我想使用matplotlib绘制jpg图像,然后覆盖(x,y)数据的散点图,该数据从文本文件中读取并存储到Pythonic列表中。下面是将绘制jpg图像的代码,但在我所做的所有matplotlib,scipy和PIL手册和帮助页面的搜索中,我找不到任何解释如何维护此绘图窗口并简单地覆盖散点图图像中各个(x,y)位置的简单标记。非常感谢任何帮助。

I need to rapidly plot jpg frames that result as the output of a tracking algorithm. Companion with the jpg frames are text files containing simple (x,y) data locating the image targets that are being tracked. I would like to use matplotlib to plot the jpg images, then overlay a scatter plot of the (x,y) data which gets read from the text file and stored into a Pythonic list. Below is code that will plot the jpg image, but in all of the scouring I have done of matplotlib, scipy, and PIL manuals and help pages, I cannot find anything that explains how to maintain this plot window and simply overlay a scatter plot of simple markers at various (x,y) locations in the image. Any help is greatly appreciated.

import matplotlib.pyplot as plt;
im = plt.imread(image_name);
implot = plt.imshow(im);
plt.show()


推荐答案

pyplot.scatter()函数由于这个原因而量身定制:

The pyplot.scatter() function was tailor made for this reason:

import matplotlib.pyplot as plt
im = plt.imread(image_name)
implot = plt.imshow(im)

# put a blue dot at (10, 20)
plt.scatter([10], [20])

# put a red dot, size 40, at 2 locations:
plt.scatter(x=[30, 40], y=[50, 60], c='r', s=40)

plt.show()

请参阅文档了解更多信息。

这篇关于如何在matplotlib / Python中直接在散焦图上叠加jpg图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆