Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在绘图窗口中放置自定义图像--作为自定义数据标记或注释这些标记_Python_R_Matplotlib_Plot - Fatal编程技术网

Python 在绘图窗口中放置自定义图像--作为自定义数据标记或注释这些标记

Python 在绘图窗口中放置自定义图像--作为自定义数据标记或注释这些标记,python,r,matplotlib,plot,Python,R,Matplotlib,Plot,我有一组150x150px的png图像,以及它们对应的一组(x,y)坐标。有没有办法在网格上绘制图像?例如,我正在寻找一个R或Python解决方案来创建如下内容: 通过实例化注释BBOX——为每个图像创建一个边界框 您希望显示的内容;图像及其坐标将传递给构造函数 对于这两幅图像,代码显然是重复的,因此,一旦将该块放入函数中,它就没有这里看起来的那么长了 import matplotlib.pyplot as PLT from matplotlib.offsetbox import Annotat

我有一组150x150px的png图像,以及它们对应的一组(x,y)坐标。有没有办法在网格上绘制图像?例如,我正在寻找一个R或Python解决方案来创建如下内容:

通过实例化注释BBOX——为每个图像创建一个边界框 您希望显示的内容;图像及其坐标将传递给构造函数

对于这两幅图像,代码显然是重复的,因此,一旦将该块放入函数中,它就没有这里看起来的那么长了

import matplotlib.pyplot as PLT
from matplotlib.offsetbox import AnnotationBbox, OffsetImage
from matplotlib._png import read_png

fig = PLT.gcf()
fig.clf()
ax = PLT.subplot(111)

# add a first image
arr_hand = read_png('/path/to/this/image.png')
imagebox = OffsetImage(arr_hand, zoom=.1)
xy = [0.25, 0.45]               # coordinates to position this image

ab = AnnotationBbox(imagebox, xy,
    xybox=(30., -30.),
    xycoords='data',
    boxcoords="offset points")                                  
ax.add_artist(ab)

# add second image
arr_vic = read_png('/path/to/this/image2.png')
imagebox = OffsetImage(arr_vic, zoom=.1)
xy = [.6, .3]                  # coordinates to position 2nd image

ab = AnnotationBbox(imagebox, xy,
    xybox=(30, -30),
    xycoords='data',
    boxcoords="offset points")
ax.add_artist(ab)

# rest is just standard matplotlib boilerplate
ax.grid(True)
PLT.draw()
PLT.show()

我会使用matplotlib。 显示了类似的内容,我相信它可以适应您的特定问题

在R(2.11.0及更高版本)中执行此操作的一种方法:

library(“png”)
#读取示例文件(R徽标)
R中的img,在帮助(光栅图像)中读取:

require(GR设备)
#设置绘图区域:

op同样在R中,您可以使用TeachingDemos包中的my.symbols和ms.image函数。

这很好,您知道如何删除边框吗?@JohnM Pass
frameon=False
to
AnnotationBbox()
相关:
library("png")
# read a sample file (R logo)
img <- readPNG(system.file("img", "Rlogo.png", package="png"))
# img2 <- readPNG(system.file("img", "Rlogo.png", package="png"))
img2 <- readPNG("hand.png", TRUE) # here import a different image 
if (exists("rasterImage")) { 
  plot(1:1000, type='n')
  rasterImage(img, 100, 100, 200, 200)
  rasterImage(img2, 300, 300, 400, 400)
}
require(grDevices)
#set up the plot region:
op <- par(bg = "thistle") <h>
plot(c(100, 250), c(300, 450), type = "n", xlab="", ylab="")
image <- as.raster(matrix(0:1, ncol=5, nrow=3))
rasterImage(image, 100, 300, 150, 350, interpolate=FALSE)
rasterImage(image, 100, 400, 150, 450)
rasterImage(image, 200, 300, 200 + xinch(.5), 300 + yinch(.3), interpolate=FALSE)
rasterImage(image, 200, 400, 250, 450, angle=15, interpolate=FALSE)
par(op)