View With Annotations

Matplotview’s views are also regular matplotlib Axes, meaning they support regular plotting on top of their viewing capabilities, allowing for annotations, as shown below.

plot 03 view with annotations
10 # All the same as from the prior inset axes example...
11 from matplotlib import cbook
12 import matplotlib.pyplot as plt
13 import numpy as np
14 from matplotview import inset_zoom_axes
15
16
17 def get_demo_image():
18     z = cbook.get_sample_data("axes_grid/bivariate_normal.npy", np_load=True)
19     return z, (-3, 4, -4, 3)
20
21
22 fig, ax = plt.subplots()
23
24 Z, extent = get_demo_image()
25 Z2 = np.zeros((150, 150))
26 ny, nx = Z.shape
27 Z2[30:30 + ny, 30:30 + nx] = Z
28
29 ax.imshow(Z2, extent=extent, interpolation='nearest', origin="lower")
30
31 axins = inset_zoom_axes(ax, [0.5, 0.5, 0.47, 0.47])
32
33 x1, x2, y1, y2 = -1.5, -0.9, -2.5, -1.9
34 axins.set_xlim(x1, x2)
35 axins.set_ylim(y1, y2)
36
37 # We'll annotate the 'interesting' spot in the view....
38 axins.annotate(
39     "Interesting Feature", (-1.3, -2.25), (0.1, 0.1),
40     textcoords="axes fraction", arrowprops=dict(arrowstyle="->")
41 )
42
43 axins.set_xticklabels([])
44 axins.set_yticklabels([])
45
46 ax.indicate_inset_zoom(axins, edgecolor="black")
47
48 fig.show()

Total running time of the script: (0 minutes 0.200 seconds)

Gallery generated by Sphinx-Gallery