@@ -1595,44 +1595,24 @@ def __init__(self, figure):
15951595 self .toolbar = None # NavigationToolbar2 will set me
15961596 self ._is_idle_drawing = False
15971597
1598- def _repr_html_ (self ):
1599- # Defer to IPython to handle html output if possible
1598+ def _repr_png_ (self ):
1599+ # Defer to IPython to handle output if possible.
16001600 if 'IPython' in sys .modules :
1601- import IPython
1602- ip = IPython .get_ipython ()
1603- # Check whether %matplotlib was run. Is there a better way?
1604- ib_list = [c for c in ip .configurables
1605- if 'InlineBackend' in type (c ).__name__ ]
1606- if ib_list :
1601+ from IPython .core .pylabtools import configure_inline_support
1602+ # Check whether %matplotlib was run.
1603+ if hasattr (configure_inline_support , 'current_backend' ):
16071604 return
1608-
1609- fmt = self .get_default_filetype ()
1610-
1611- kw = {
1612- "format" :fmt ,
1613- "facecolor" :self .figure .get_facecolor (),
1614- "edgecolor" :self .figure .get_edgecolor (),
1615- "dpi" :self .figure .dpi ,
1616- "bbox_inches" :self .figure .bbox_inches
1617- }
1618-
1619- bytes_io = io .BytesIO ()
1620- self .print_figure (bytes_io , ** kw )
1621- raw_bytes = bytes_io .getvalue ()
1622-
1623- from base64 import b64encode
1624- data = b64encode (raw_bytes ).decode ()
1625-
1626- if fmt == 'svg' :
1627- return raw_bytes .decode ()
1628- elif fmt == 'png' :
1629- return f'<img src="data:image/png;base64, { data } " />'
1630- elif fmt == 'pdf' :
1631- w , h = self .figure .get_size_inches ()
1632- w , h = w * self .figure .dpi , h * self .figure .dpi
1633- return f'<embed width="{ w } " height="{ h } " src="data:application/pdf;base64, { data } ">'
1634- elif fmt == 'jpg' :
1635- return f'<img src="data:image/jpeg;base64, { data } " />'
1605+
1606+ png_bytes = io .BytesIO ()
1607+ self .print_figure (
1608+ png_bytes ,
1609+ format = 'png' ,
1610+ facecolor = self .figure .get_facecolor (),
1611+ edgecolor = self .figure .get_edgecolor (),
1612+ dpi = self .figure .dpi ,
1613+ bbox_inches = self .figure .bbox_inches
1614+ )
1615+ return png_bytes .getvalue ()
16361616
16371617 @classmethod
16381618 @functools .lru_cache ()
0 commit comments