Created
February 18, 2019 13:52
-
-
Save MortisHuang/e14b4f6095d5436c41c4a9125a94f1d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
from matplotlib.offsetbox import OffsetImage, AnnotationBbox | |
import numpy as np; np.random.seed(42) | |
# Generate data x, y for scatter and an array of images. | |
x = np.arange(20) | |
y = np.random.rand(len(x)) | |
arr = np.empty((len(x),10,10)) | |
for i in range(len(x)): | |
f = np.random.rand(5,5) | |
arr[i, 0:5,0:5] = f | |
arr[i, 5:,0:5] =np.flipud(f) | |
arr[i, 5:,5:] =np.fliplr(np.flipud(f)) | |
arr[i, 0:5:,5:] = np.fliplr(f) | |
# create figure and plot scatter | |
fig = plt.figure() | |
ax = fig.add_subplot(111) | |
line, = ax.plot(x,y, ls="", marker="o") | |
# create the annotations box | |
im = OffsetImage(arr[0,:,:], zoom=5) | |
xybox=(50, 50) | |
ab = AnnotationBbox(im, (x[0],y[0]), xybox=xybox, xycoords='data', | |
boxcoords="offset points", pad=0.3, arrowprops=dict(arrowstyle="->")) | |
# add it to the axes and make it invisible | |
ax.add_artist(ab) | |
ab.set_visible(True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment