Skip to content

Commit 2ec3897

Browse files
committed
fixed code to display plots given as arrays of plotting axes (as returned by .plot(subplots=True))
* avoid an exception whenever we try to display any empty sequence (whether it contains plots or not) * avoid copying the whole sequence just to get the first element for non array sequences. This loose the ability to display plots hidden in nested sequences (instead of ndarrays) but I am unsure doing that even for simple sequences is useful anyway
1 parent 1042c1a commit 2ec3897

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

doc/source/changes/version_0_32_2.rst.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. py:currentmodule:: larray_editor
1+
.. py:currentmodule:: larray_editor
22

33
Syntax changes
44
^^^^^^^^^^^^^^
@@ -38,4 +38,4 @@ Miscellaneous improvements
3838
Fixes
3939
^^^^^
4040

41-
* fixed something (closes :editor_issue:`1`).
41+
* fixed spurious warning in the console when an expression results in an empty sequence (array, list, tuple).

larray_editor/editor.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -694,15 +694,24 @@ def ipython_cell_executed(self):
694694
# last command. Which means that if the last command did not produce any output, _ is not modified.
695695
cur_output = user_ns['_oh'].get(cur_input_num)
696696
if cur_output is not None:
697+
if 'inline' not in matplotlib.get_backend():
698+
if isinstance(cur_output, np.ndarray) and cur_output.size > 0:
699+
first_output = cur_output.flat[0]
700+
if isinstance(first_output, matplotlib.axes.Subplot):
701+
show_figure(self, first_output.figure)
702+
# we use a different path for sequences than for arrays to avoid copying potentially
703+
# big non-array sequences using np.ravel(). This code does not support nested sequences,
704+
# but I am already unsure supporting simple non-array sequences is useful.
705+
elif isinstance(cur_output, collections.Sequence) and len(cur_output) > 0:
706+
first_output = cur_output[0]
707+
if isinstance(first_output, matplotlib.axes.Subplot):
708+
show_figure(self, first_output.figure)
709+
elif isinstance(cur_output, matplotlib.axes.Subplot):
710+
show_figure(self, cur_output.figure)
711+
697712
if self._display_in_grid('<expr>', cur_output):
698713
self.view_expr(cur_output)
699714

700-
if isinstance(cur_output, collections.Iterable):
701-
cur_output = np.ravel(cur_output)[0]
702-
703-
if isinstance(cur_output, matplotlib.axes.Subplot) and 'inline' not in matplotlib.get_backend():
704-
show_figure(self, cur_output.figure)
705-
706715
def on_selection_changed(self):
707716
selected = self._listwidget.selectedItems()
708717
if selected:

0 commit comments

Comments
 (0)