用图像替换散点图上的点

时间:2020-11-03 14:35:45

标签: python image numpy matplotlib scatter-plot

我试图使用matplotlib显示散点图,但我不想将其表示为点,而是希望将其显示为图像(取决于'type'属性)。例如,如果对象的类型为“狗”,则图使用狗图像等。我已经尝试了AnnotationBox,但找不到足够的在线资源来帮助我进行尝试。

到目前为止,这是我的代码,希望可以更好地解释我的工作。

import matplotlib.pyplot as plt
import numpy as np

class PlotPoint():
    def __init__(self, x, y, species):
        self.x = x
        self.y = y
        self.species = species

# 4 animals: 3 Dogs, 1 Cat
plots = np.empty([4], dtype='object')
plots[0] = PlotPoint(1,1,"dog")
plots[1] = PlotPoint(2,2,"cat")
plots[2] = PlotPoint(3,3,"dog")
plots[3] = PlotPoint(4,4,"dog")

for plot in plots:
    if plot.species == 'dog':
        # **** PLOT AS DOG IMAGE HERE **** #
        plt.scatter(plot.x, plot.y)
    if plot.species == 'cat':
        # **** PLOT AS CAT IMAGE HERE **** #
        plt.scatter(plot.x, plot.y)

0 个答案:

没有答案