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

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

问题描述

我需要快速绘制作为跟踪算法输出结果的 jpg 帧.与 jpg 帧相伴的是包含简单 (x,y) 数据的文本文件,用于定位正在跟踪的图像目标.我想使用 matplotlib 绘制 jpg 图像,然后覆盖从文本文件中读取并存储到 Pythonic 列表中的 (x,y) 数据的散点图.下面是绘制 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()

有关详细信息,请参阅文档.

See the documentation for more info.

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

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