@@ -1701,44 +1701,24 @@ def __init__(self, figure):
17011701 self .toolbar = None # NavigationToolbar2 will set me
17021702 self ._is_idle_drawing = False
17031703
1704- def _repr_html_ (self ):
1705- # Defer to IPython to handle html output if possible
1704+ def _repr_png_ (self ):
1705+ # Defer to IPython to handle output if possible.
17061706 if 'IPython' in sys .modules :
1707- import IPython
1708- ip = IPython .get_ipython ()
1709- # Check whether %matplotlib was run. Is there a better way?
1710- ib_list = [c for c in ip .configurables
1711- if 'InlineBackend' in type (c ).__name__ ]
1712- if ib_list :
1707+ from IPython .core .pylabtools import configure_inline_support
1708+ # Check whether %matplotlib was run.
1709+ if hasattr (configure_inline_support , 'current_backend' ):
17131710 return
1714-
1715- fmt = self .get_default_filetype ()
1716-
1717- kw = {
1718- "format" :fmt ,
1719- "facecolor" :self .figure .get_facecolor (),
1720- "edgecolor" :self .figure .get_edgecolor (),
1721- "dpi" :self .figure .dpi ,
1722- "bbox_inches" :self .figure .bbox_inches
1723- }
17241711
1725- bytes_io = io .BytesIO ()
1726- self .print_figure (bytes_io , ** kw )
1727- raw_bytes = bytes_io .getvalue ()
1728-
1729- from base64 import b64encode
1730- data = b64encode (raw_bytes ).decode ()
1731-
1732- if fmt == 'svg' :
1733- return raw_bytes .decode ()
1734- elif fmt == 'png' :
1735- return f'<img src="data:image/png;base64, { data } " />'
1736- elif fmt == 'pdf' :
1737- w , h = self .figure .get_size_inches ()
1738- w , h = w * self .figure .dpi , h * self .figure .dpi
1739- return f'<embed width="{ w } " height="{ h } " src="data:application/pdf;base64, { data } ">'
1740- elif fmt == 'jpg' :
1741- return f'<img src="data:image/jpeg;base64, { data } " />'
1712+ png_bytes = io .BytesIO ()
1713+ self .print_figure (
1714+ png_bytes ,
1715+ format = 'png' ,
1716+ facecolor = self .figure .get_facecolor (),
1717+ edgecolor = self .figure .get_edgecolor (),
1718+ dpi = self .figure .dpi ,
1719+ bbox_inches = self .figure .bbox_inches
1720+ )
1721+ return png_bytes .getvalue ()
17421722
17431723 @classmethod
17441724 @functools .lru_cache ()
0 commit comments