Python 使用matplotlib绘制img
我想为演示文稿绘制一些点,但是,有没有办法绘制png图像,比如Python 使用matplotlib绘制img,python,visualization,Python,Visualization,我想为演示文稿绘制一些点,但是,有没有办法绘制png图像,比如 plt.scatter(X,Y, img='figure.png') matplotlib中的注释框模块有助于在可视化中打印图像而不是点 import numpy as np import matplotlib.pyplot as plt from matplotlib.offsetbox import OffsetImage, AnnotationBbox from matplotlib.cbook import get_sam
plt.scatter(X,Y, img='figure.png')
matplotlib中的
注释框
模块有助于在可视化中打印图像而不是点
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.offsetbox import OffsetImage, AnnotationBbox
from matplotlib.cbook import get_sample_data
def main():
x = np.linspace(0, 10, 20)
y = np.cos(x)
image_path = get_sample_data('pic.png')
fig, ax = plt.subplots()
imscatter(x, y, image_path, zoom=0.1, ax=ax)
ax.plot(x, y)
plt.show()
def imscatter(x, y, image, ax=None, zoom=1):
if ax is None:
ax = plt.gca()
try:
image = plt.imread(image)
except TypeError:
pass
im = OffsetImage(image, zoom=zoom)
x, y = np.atleast_1d(x, y)
artists = []
for x0, y0 in zip(x, y):
ab = AnnotationBbox(im, (x0, y0), xycoords='data', frameon=False)
artists.append(ax.add_artist(ab))
ax.update_datalim(np.column_stack([x, y]))
ax.autoscale()
return artists
main()
生成的图像: