matplotview.inset_zoom_axes()
can be utilized to create inset axes where we don’t have to plot the parent axes data twice.
9 from matplotlib import cbook 10 import matplotlib.pyplot as plt 11 import numpy as np 12 from matplotview import inset_zoom_axes 13 14 def get_demo_image(): 15 z = cbook.get_sample_data("axes_grid/bivariate_normal.npy", np_load=True) 16 # z is a numpy array of 15x15 17 return z, (-3, 4, -4, 3) 18 19 fig, ax = plt.subplots() 20 21 # Make the data... 22 Z, extent = get_demo_image() 23 Z2 = np.zeros((150, 150)) 24 ny, nx = Z.shape 25 Z2[30:30+ny, 30:30+nx] = Z 26 27 ax.imshow(Z2, extent=extent, interpolation='nearest', origin="lower") 28 29 # Creates an inset axes with automatic view of the parent axes... 30 axins = inset_zoom_axes(ax, [0.5, 0.5, 0.47, 0.47]) 31 # Set limits to sub region of the original image 32 x1, x2, y1, y2 = -1.5, -0.9, -2.5, -1.9 33 axins.set_xlim(x1, x2) 34 axins.set_ylim(y1, y2) 35 36 # Remove the tick labels from the inset axes 37 axins.set_xticklabels([]) 38 axins.set_yticklabels([]) 39 40 # Draw the indicator or zoom lines. 41 ax.indicate_inset_zoom(axins, edgecolor="black") 42 43 fig.show()
Total running time of the script: (0 minutes 0.190 seconds)
Gallery generated by Sphinx-Gallery
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4