2525)
2626from ._utils .context import plot_context
2727from ._utils .ipython import (
28- get_display_function ,
2928 get_ipython ,
3029 get_mimebundle ,
3130 is_inline_backend ,
5655 from plotnine .composition import Compose
5756 from plotnine .coords .coord import coord
5857 from plotnine .facets .facet import facet
59- from plotnine .typing import DataLike , FigureFormat
58+ from plotnine .typing import DataLike , FigureFormat , MimeBundle
6059
6160 class PlotAddable (Protocol ):
6261 """
@@ -138,11 +137,15 @@ def __str__(self) -> str:
138137 w , h = self .theme ._figure_size_px
139138 return f"<ggplot: ({ w } x { h } )>"
140139
141- def _repr_mimebundle_ (self , ** kwargs ) :
140+ def _repr_mimebundle_ (self , include = None , exclude = None ) -> MimeBundle :
142141 """
143142 Return dynamic MIME bundle for plot display
144143
145144 This method is called when a ggplot object is the last in the cell.
145+
146+ Notes
147+ -----
148+ - https://ipython.readthedocs.io/en/stable/config/integrating.html
146149 """
147150 ip = get_ipython ()
148151 format : FigureFormat = (
@@ -166,34 +169,21 @@ def show(self):
166169 """
167170 Show plot using the matplotlib backend set by the user
168171
169- Users should prefer this method instead of printing or repring
170- the object.
172+ This function is called for its side-effects.
171173 """
172174 # Prevent against any modifications to the users
173175 # ggplot object. Do the copy here as we may/may not
174176 # assign a default theme
175177 self = deepcopy (self )
176178
177179 if is_inline_backend () or is_quarto_environment ():
178- # Take charge of the display because we have to make
179- # adjustments for retina output.
180- self ._display ()
180+ from IPython .display import display
181+
182+ data , metadata = self ._repr_mimebundle_ ()
183+ display (data , metadata = metadata , raw = True )
181184 else :
182185 self .draw (show = True )
183186
184- def _display (self ):
185- """
186- Display plot in the cells output
187-
188- This function is called for its side-effects.
189-
190- It plots the plot to an io buffer, then uses ipython display
191- methods to show the result
192- """
193- data , metadata = self ._repr_mimebundle_ ()
194- display_func = get_display_function ()
195- display_func (data , metadata )
196-
197187 def __deepcopy__ (self , memo : dict [Any , Any ]) -> ggplot :
198188 """
199189 Deep copy without copying the dataframe and environment
0 commit comments