Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c0f682d

Browse files
committed
DOC: add demo code to example
1 parent 2c054de commit c0f682d

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

examples/user_interfaces/mplcvd.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def _get_color_filter(name):
5858
5959
def filter(input: np.ndarray[M, N, D])-> np.ndarray[M, N, D]
6060
61-
where (M, N) are the image dimentions, and D is the color depth (3 for
61+
where (M, N) are the image dimensions, and D is the color depth (3 for
6262
RGB, 4 for RGBA). Alpha is passed through unchanged and otherwise
6363
ignored.
6464
"""
@@ -259,3 +259,48 @@ def _setup_wx(tb):
259259
id=item.Id,
260260
)
261261
tb.SetDropdownMenu(tool.Id, menu)
262+
263+
264+
if __name__ == '__main__':
265+
import matplotlib.pyplot as plt
266+
from matplotlib import cbook
267+
268+
plt.rcParams['figure.hooks'].append('mplcvd:setup')
269+
270+
fig, axd = plt.subplot_mosaic(
271+
[
272+
['viridis', 'turbo'],
273+
['photo', 'lines']
274+
]
275+
)
276+
277+
delta = 0.025
278+
x = y = np.arange(-3.0, 3.0, delta)
279+
X, Y = np.meshgrid(x, y)
280+
Z1 = np.exp(-X**2 - Y**2)
281+
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
282+
Z = (Z1 - Z2) * 2
283+
284+
imv = axd['viridis'].imshow(
285+
Z, interpolation='bilinear',
286+
origin='lower', extent=[-3, 3, -3, 3],
287+
vmax=abs(Z).max(), vmin=-abs(Z).max()
288+
)
289+
fig.colorbar(imv)
290+
imt = axd['turbo'].imshow(
291+
Z, interpolation='bilinear', cmap='turbo',
292+
origin='lower', extent=[-3, 3, -3, 3],
293+
vmax=abs(Z).max(), vmin=-abs(Z).max()
294+
)
295+
fig.colorbar(imt)
296+
297+
# A sample image
298+
with cbook.get_sample_data('grace_hopper.jpg') as image_file:
299+
photo = plt.imread(image_file)
300+
axd['photo'].imshow(photo)
301+
302+
th = np.linspace(0, 2*np.pi, 1024)
303+
for j in [1, 2, 4, 6]:
304+
axd['lines'].plot(th, np.sin(th * j), label=f'$\\omega={j}$')
305+
axd['lines'].legend(ncol=2, loc='upper right')
306+
plt.show()

0 commit comments

Comments
 (0)