|
4 | 4 | from matplotlib import cm |
5 | 5 | from matplotlib.figure import Figure |
6 | 6 | from matplotlib import animation |
7 | | -try: |
8 | | - from IPython.display import HTML |
9 | | -except ImportError: |
10 | | - warnings.warn("Unable to import IPython.display.HTML, animshow must be called with " |
11 | | - "as_html5=False") |
12 | 7 | from ..pyramids import convert_pyr_coeffs_to_pyr |
13 | 8 |
|
14 | 9 |
|
@@ -529,16 +524,18 @@ def _process_signal(signal, title, plot_complex, video=False): |
529 | 524 | if sig.ndim == (3 + time_dim): |
530 | 525 | if sig.shape[-1] not in [3, 4]: |
531 | 526 | raise Exception( |
532 | | - "Can't figure out how to plot {} with shape {}" |
| 527 | + f"Can't figure out how to plot {sigtype} with shape {sig.shape} " |
533 | 528 | "as RGB(A)! RGB(A) signals should have their final" |
534 | | - "dimension of shape 3 or 4.".format(sigtype, sig.shape)) |
| 529 | + "dimension of shape 3 or 4." |
| 530 | + ) |
535 | 531 | contains_rgb = True |
536 | 532 | elif sig.ndim != (2 + time_dim): |
537 | 533 | raise Exception( |
538 | | - "Can't figure out how to plot image with " |
539 | | - "shape {}! Images should be be either 2d " |
540 | | - "(grayscale) or 3d (RGB(A), last dimension with 3 or" |
541 | | - " 4 elements).".format(sig.shape)) |
| 534 | + f"Can't figure out how to plot {sigtype} with " |
| 535 | + f"shape {sig.shape}! {sigtype.capitalize()}s should be be either " |
| 536 | + f"{2 + time_dim}d (grayscale) or {3 + time_dim}d (RGB(A), last " |
| 537 | + "dimension with 3 or 4 elements)." |
| 538 | + ) |
542 | 539 | if np.iscomplexobj(sig): |
543 | 540 | if plot_complex == 'rectangular': |
544 | 541 | signal_tmp.extend([np.real(sig), np.imag(sig)]) |
@@ -776,6 +773,7 @@ def animshow(video, framerate=2., as_html5=True, repeat=False, |
776 | 773 | as_html : `bool` |
777 | 774 | If True, return an HTML5 video; otherwise return the underying matplotlib animation object |
778 | 775 | (e.g. to save to .gif). should set to True to display in a Jupyter notebook. |
| 776 | + Requires ipython to be installed. |
779 | 777 | repeat : `bool` |
780 | 778 | whether to loop the animation or just play it once |
781 | 779 | vrange : `tuple` or `str` |
@@ -832,7 +830,12 @@ def animshow(video, framerate=2., as_html5=True, repeat=False, |
832 | 830 | Animation, format depends on `as_html`. |
833 | 831 |
|
834 | 832 | """ |
835 | | - |
| 833 | + if as_html5: |
| 834 | + try: |
| 835 | + from IPython.display import HTML |
| 836 | + except ImportError: |
| 837 | + raise ImportError("Unable to import IPython.display.HTML, animshow must be called with " |
| 838 | + "as_html5=False") |
836 | 839 | video = _convert_signal_to_list(video) |
837 | 840 | video_n_frames = np.array([v.shape[0] for v in video]) |
838 | 841 | if (video_n_frames != video_n_frames[0]).any(): |
|
0 commit comments