Skip to content

Commit

Permalink
display MatplotlibViewer with retina as appropriate
Browse files Browse the repository at this point in the history
Addresses usnistgov#584
  • Loading branch information
guyer committed Sep 17, 2018
1 parent 10bb2f8 commit c81fbe1
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions fipy/viewers/matplotlibViewer/matplotlibViewer.py
Expand Up @@ -58,6 +58,30 @@ def _isnotebook():
except (ImportError, NameError):
return False # Probably standard Python interpreter

def _isretina():
"""return True if jupyter notebook configuration
InlineBackend.figure_formats contains 'retina' or
InlineBackend.figure_format is set to 'retina'
"""
isretina = False

try:
import IPython

cfg = IPython.get_ipython().config

if "InlineBackend" in cfg:
inbk = cfg["InlineBackend"]
if "figure_formats" in inbk:
if "retina" in inbk["figure_formats"]:
isretina = True
if not isretina and ("figure_format" in inbk):
isretina = inbk["figure_format"] == "retina"
except ImportError:
pass

return isretina

class AbstractMatplotlibViewer(AbstractViewer):
"""
.. attention:: This class is abstract. Always create one of its subclasses.
Expand Down Expand Up @@ -201,10 +225,14 @@ def _repr_png_(self):
Invoke with `display(myViewer)`
"""
from IPython.core.pylabtools import print_figure

self.plot()
return print_figure(self.axes.get_figure(), "png")
from IPython.core.pylabtools import print_figure, retina_figure

fig = self.axes.get_figure()

if _isretina():
return retina_figure(fig)
else:
return print_figure(fig, "png")

class _ColorBar(object):
def __init__(self, viewer, vmin=-1, vmax=1, orientation="vertical"):
Expand Down

0 comments on commit c81fbe1

Please sign in to comment.