def _repr_svg_(self): """Returns an SVG representation of this plot as a string. This method is used by IPython to display this plot inline. """ io = BytesIO() # Create a new SVG surface and use that to get the SVG representation, # which will end up in io surface = cairo.SVGSurface(io, self.bbox.width, self.bbox.height) context = cairo.Context(surface) # Plot the graph on this context self.redraw(context) # No idea why this is needed but python crashes without context.show_page() surface.finish() # Return the raw SVG representation return io.getvalue().decode("utf-8")
def _repr_svg_(self): """Returns an SVG representation of this plot as a string. This method is used by IPython to display this plot inline. """ io = BytesIO() # Create a new SVG surface and use that to get the SVG representation, # which will end up in io surface = cairo.SVGSurface(io, self.bbox.width, self.bbox.height) context = cairo.Context(surface) # Plot the graph on this context self.redraw(context) # No idea why this is needed but python crashes without context.show_page() surface.finish() # Return the raw SVG representation return io.getvalue().encode("utf-8")
def _ensure_uncompressed(response): """Expects an HTTP response object, checks its Content-Encoding header, decompresses the data and returns an in-memory buffer holding the uncompressed data.""" compressed = response.headers.get("Content-Encoding") == "gzip" if not compressed: content_disp = response.headers.get("Content-Disposition", "") compressed = bool( re.match(r'attachment; *filename=.*\.gz\"?$', content_disp)) if compressed: return GzipFile(fileobj=BytesIO(response.read()), mode="rb") return response
def _repr_svg_(self): """Returns an SVG representation of this plot as a string. This method is used by IPython to display this plot inline. """ io = BytesIO() # Create a new SVG surface and use that to get the SVG representation, # which will end up in io surface = cairo.SVGSurface(io, self.bbox.width, self.bbox.height) context = cairo.Context(surface) # Plot the graph on this context self.redraw(context) # No idea why this is needed but python crashes without context.show_page() surface.finish() # Return the raw SVG representation result = io.getvalue() if hasattr(result, "encode"): result = result.encode("utf-8") # for Python 2.x else: result = result.decode("utf-8") # for Python 3.x return result, {'isolated': True} # put it inside an iframe
def _repr_svg_(self): """Returns an SVG representation of this plot as a string. This method is used by IPython to display this plot inline. """ io = BytesIO() # Create a new SVG surface and use that to get the SVG representation, # which will end up in io surface = cairo.SVGSurface(io, self.bbox.width, self.bbox.height) context = cairo.Context(surface) # Plot the graph on this context self.redraw(context) # No idea why this is needed but python crashes without context.show_page() surface.finish() # Return the raw SVG representation result = io.getvalue() if hasattr(result, "encode"): result = result.encode("utf-8") # for Python 2.x else: result = result.decode("utf-8") # for Python 3.x return result, {'isolated': True} # put it inside an iframe