diff --git a/IPython/core/pylabtools.py b/IPython/core/pylabtools.py index fa6c6f9..4bf15cc 100644 --- a/IPython/core/pylabtools.py +++ b/IPython/core/pylabtools.py @@ -123,6 +123,10 @@ def print_figure(fig, fmt='png', bbox_inches='tight', **kwargs): def retina_figure(fig, **kwargs): """format a figure as a pixel-doubled (retina) PNG""" pngdata = print_figure(fig, fmt='retina', **kwargs) + # Make sure that retina_figure acts just like print_figure and returns + # None when the figure is empty. + if pngdata is None: + return w, h = _pngxy(pngdata) metadata = dict(width=w//2, height=h//2) return pngdata, metadata diff --git a/IPython/core/tests/test_pylabtools.py b/IPython/core/tests/test_pylabtools.py index 67c45d2..aa9d16b 100644 --- a/IPython/core/tests/test_pylabtools.py +++ b/IPython/core/tests/test_pylabtools.py @@ -66,6 +66,11 @@ def test_figure_to_jpeg(): assert jpeg.startswith(_JPEG) def test_retina_figure(): + # simple empty-figure test + fig = plt.figure() + nt.assert_equal(pt.retina_figure(fig), None) + plt.close('all') + fig = plt.figure() ax = fig.add_subplot(1,1,1) ax.plot([1,2,3])