diff --git a/IPython/core/pylabtools.py b/IPython/core/pylabtools.py index 6755fb8..40cbabb 100644 --- a/IPython/core/pylabtools.py +++ b/IPython/core/pylabtools.py @@ -173,13 +173,22 @@ def select_figure_format(shell, fmt): png_formatter = shell.display_formatter.formatters['image/png'] if fmt == 'png': - svg_formatter.type_printers.pop(Figure, None) + try: + svg_formatter.pop(Figure) + except KeyError: + pass png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png')) elif fmt in ('png2x', 'retina'): - svg_formatter.type_printers.pop(Figure, None) + try: + svg_formatter.pop(Figure) + except KeyError: + pass png_formatter.for_type(Figure, retina_figure) elif fmt == 'svg': - png_formatter.type_printers.pop(Figure, None) + try: + svg_formatter.pop(Figure) + except KeyError: + pass svg_formatter.for_type(Figure, lambda fig: print_figure(fig, 'svg')) else: raise ValueError("supported formats are: 'png', 'retina', 'svg', not %r" % fmt)