-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathplot_11_image_interpolation.py
More file actions
52 lines (40 loc) · 1.51 KB
/
plot_11_image_interpolation.py
File metadata and controls
52 lines (40 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
Image Interpolation Methods
===========================
:meth:`matplotview.view` and :meth:`matplotview.inset_zoom_axes` support specifying an
image interpolation method via the `image_interpolation` parameter. This image interpolation
method is used to resize images when displaying them in the view.
"""
import matplotlib.pyplot as plt
from matplotview import view
import numpy as np
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2)
fig.suptitle("Different interpolations when zoomed in on the bottom left corner.")
ax1.set_title("Original")
ax1.imshow(np.random.rand(100, 100), cmap="Blues", origin="lower")
ax1.add_patch(plt.Rectangle((0, 0), 10, 10, ec="red", fc=(0, 0, 0, 0)))
for ax, interpolation, title in zip([ax2, ax3, ax4], ["nearest", "bilinear", "bicubic"], ["Nearest (Default)", "Bilinear", "Cubic"]):
ax.set_title(title)
ax.set_xlim(0, 10)
ax.set_ylim(0, 10)
ax.set_aspect("equal")
view(ax, ax1, image_interpolation=interpolation)
fig.tight_layout()
fig.show()
#%%
# If you want to avoid interpolation artifacts, you can use `pcolormesh` instead of `imshow`.
import matplotlib.pyplot as plt
from matplotview import view
import numpy as np
fig, (ax1, ax2) = plt.subplots(1, 2)
ax1.set_title("Original")
ax1.pcolormesh(np.random.rand(100, 100), cmap="Blues")
ax1.add_patch(plt.Rectangle((0, 0), 10, 10, ec="red", fc=(0, 0, 0, 0)))
ax1.set_aspect("equal")
ax2.set_title("Zoomed in View")
ax2.set_xlim(0, 10)
ax2.set_ylim(0, 10)
ax2.set_aspect("equal")
view(ax2, ax1)
fig.tight_layout()
fig.show()