Creating custom plots: Extend Figure class?

I would like to create a custom plot type for which the user can make specialized settings as a way to simplify the usage of a particular stereotypical plot type that comes up repeatedly in my work. For instance, some settings involve transforming the data that go into plotting, others change two or more plot properties at once to compensate for each other. Users should be able to make settings to an object from which the resulting plot can change.

How would I go about this? I tried to extend the Figure class, but it seems discouraged, as new public attributes are prevented from being set in a class that inherits from Figure. Is the solution something other than a class?

Hi @andom, I usually create functions which return the desired graph.

Thanks @AIMPED, this is currently also how I do it. I just thought it would be nice to be able to have controls over a custom plot, say, when it’s a combination of several subplots, so controls are aware of its structure and act on a higher level than the plotly elements (subplots, annotations, traces) that make it up. For instance, in the attached example, I’d like to let the user shift annotations at the bottom right, or the placement of the bottom right plot and legend according to how the numbers turn out (given that I will not implement an automatic mechanism to take care of this).

I understand. Have you ever thought of using dash for these kind of interactiveness?

By β€œuser”, I mean basically myself or a colleague using a concise function call to make such a plot from a given dataset that has a recurring shape. The motivation of trying to make it a class (or function) is in response to this recurrence, so I want to make it a re-usable structure. I don’t need it to be interactive in the way that dash allows.

And more generally, I am interested in whether there is a way of making new plot types by building them from plotly elements. It would be nice to have a bunch of re-usable forms for recurring problems that are specific to my work environment.

1 Like