Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[ENH]: Add_repr_svg_ etc toFigure #25846

Open
@oscargus

Description

@oscargus

Problem

Jupyter Qt Console, Spyder and probably Jupyter Notebooks and others can display enriched formats for objects.

It would be convenient ifFigure (and possibly other Artists where possible) returned these.

Note that this is different from%matplotlib inline in the sense that the object returns its own representation, not that it plots inline. Although from some perspective it is the same thing. However, I'd like to be able to do something like

fig,ax=plt.subplots()...fig

and thenfig is shown inline.

And to be even more specific. I have a class where I would like to be able to return different "views" of it in this way. The class already have a_repr_svg_-method (which returns an SVG generated from Matplotlib), but I would like to have properties that returns an object with a different_repr_svg_. One way is to use a simple wrapper, similar to:
https://stackoverflow.com/questions/72613209/displaying-a-matplotlib-figure-from-a-custom-class-in-jupyter-notebook (although a bit more code is required), but maybe we would like to support this directly?

Related to#16782

Proposed solution

Add_repr_svg_,_repr_png_, and maybe some more methods (possibly_repr_mimebundle_). The main question is when these are called and if it brings any performance penalties for people not relying on this?

Something like this will do:

def_repr_svg_(self):buffer=io.StringIO()self.savefig(buffer,format="svg")returnbuffer.getvalue()

but this should be discussed before any PR is created.

There are a few methods like this already. Colors can draw themselves and I now see that there is a_repr_html_ forFigure. As well as something for a font entry.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp