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

Skip to content

Commit e6eecba

Browse files
tacaswellanntzer
authored andcommitted
DOC: add demo code to example
1 parent 9e113c9 commit e6eecba

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
@@ -51,7 +51,7 @@ def _get_color_filter(name):
5151
5252
def filter(input: np.ndarray[M, N, D])-> np.ndarray[M, N, D]
5353
54-
where (M, N) are the image dimentions, and D is the color depth (3 for
54+
where (M, N) are the image dimensions, and D is the color depth (3 for
5555
RGB, 4 for RGBA). Alpha is passed through unchanged and otherwise
5656
ignored.
5757
"""
@@ -252,3 +252,48 @@ def _setup_wx(tb):
252252
id=item.Id,
253253
)
254254
tb.SetDropdownMenu(tool.Id, menu)
255+
256+
257+
if __name__ == '__main__':
258+
import matplotlib.pyplot as plt
259+
from matplotlib import cbook
260+
261+
plt.rcParams['figure.hooks'].append('mplcvd:setup')
262+
263+
fig, axd = plt.subplot_mosaic(
264+
[
265+
['viridis', 'turbo'],
266+
['photo', 'lines']
267+
]
268+
)
269+
270+
delta = 0.025
271+
x = y = np.arange(-3.0, 3.0, delta)
272+
X, Y = np.meshgrid(x, y)
273+
Z1 = np.exp(-X**2 - Y**2)
274+
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
275+
Z = (Z1 - Z2) * 2
276+
277+
imv = axd['viridis'].imshow(
278+
Z, interpolation='bilinear',
279+
origin='lower', extent=[-3, 3, -3, 3],
280+
vmax=abs(Z).max(), vmin=-abs(Z).max()
281+
)
282+
fig.colorbar(imv)
283+
imt = axd['turbo'].imshow(
284+
Z, interpolation='bilinear', cmap='turbo',
285+
origin='lower', extent=[-3, 3, -3, 3],
286+
vmax=abs(Z).max(), vmin=-abs(Z).max()
287+
)
288+
fig.colorbar(imt)
289+
290+
# A sample image
291+
with cbook.get_sample_data('grace_hopper.jpg') as image_file:
292+
photo = plt.imread(image_file)
293+
axd['photo'].imshow(photo)
294+
295+
th = np.linspace(0, 2*np.pi, 1024)
296+
for j in [1, 2, 4, 6]:
297+
axd['lines'].plot(th, np.sin(th * j), label=f'$\\omega={j}$')
298+
axd['lines'].legend(ncol=2, loc='upper right')
299+
plt.show()

0 commit comments

Comments
 (0)