-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
plotly.io.renderer proposal #1459
Comments
I like this a lot! |
See #1474 for implementation |
Done in #1474 |
renderer="colab+notebook_connected" does not work together when a 3d surface is plotted. |
Given that this great modular design has been implemented, would there be any renderer that can be recommended for headless testing of code where plotly.show() is being used? Maybe something that is used by plotly's python own test code? |
Yes, for headless testing, we export figures to PNG using Kaleido: https://plotly.com/python/static-image-export/ |
Overview
This issue is a design proposal for a new renderer abstraction for plotly.py to replace the
iplot
functions.Goals
Several goals motivate this work
plotly.plotly
stuff) will be split off into a separate package for v4, and the remainingplotly
package will be only "offline" only. So having the "offline" language will be unnecessary and potentially confusing.Background
There are currently 2 ways to display plots in plotly.py in "offline" mode:
plotly.offline.iplot
: This will display plots inline in a Jupyter Notebook or in JupyterLab. The use in the classic notebook requires callingplotly.offline.init_notebook_mode()
to initialize the notebook before rendering. The use in JupyterLab requires the@jupyterlab/plotly-extension
plotly.offline.plot
: This will save the plot to a standalone HTML file and, by default, open it in the default system web browser.Design Influences
This design is somewhat inspired by the approach used by the Altair project (https://altair-viz.github.io/user_guide/renderers.html), and I expect the Altair implementation will be very helpful reference during the implementation phase of this effort.
The design also draws on elements of the
plotly.io.templates
design (See #1224), and is intended to have a consistent user experience.API
Default renderer
I propose we add a new configuration object named
renderers
in theplotly.io
module. This will sit alongside theplotly.io.templates
andplotly.io.orca
configuration objects. Users will view and specify the current default renderer using property assignment. For example, to specify the equivalent ofplotly.offline.iplot
:Here are some other
mimetype-based.
renderer optionsIn addition to the mime type based renderers for use in a Jupyter context, we can support additional renderers that display figures externally (not inline). For example
Combining renderers
Multiple renderers can be registered as the default by separating the renderer names with
'+'
characters. This is the same combination syntax used to combine templates inplotly.io.templates
. When multiple mime type renderers are specified this way, a single bundle will be created with the render representation for each one. As motivation, considerA notebook with this renderer specification would display figures properly in the classic notebook ('notebook'), in jupyterlab ('jupyterlab'), in exported HTML ('notebook'), in the QtConsole/PyCharm ('png'), and in exported PDFs ('png').
Of course this would result in fairly large notebook sizes, but the user will have the flexibility to define where this code needs to render figures.
repr and show
There will be two ways to display figures. If one or more mime-type based renderers are defined and the
plotly.io.renderers.render_on_display
property is set toTrue
, then thego.Figure
instances will display themself automatically as their notebook representation. Ifplotly.io.renderers.render_on_display
is set toFalse
, then mimetype based rendering will not be performed when figures are displayed.In addition, all renderer types (including external renderers) can be invokes using a new
plotly.io.show
function. This function will display the figure as a side effect and will returnNone
.The
show
functions will also allow the user to override the default renderer. e.g.Customize renderer properties
Some renderers may need to expose additional configuration options. In this case the default renderer can be specified as an instance of the corresponding class. Each built-in renderer will be defined by a class accessible under
plotly.io.renderers
.E.g. to specify a static image renderer with custom properties:
Or the properties of an existing renderer can be modified directly:
Or the properties can be overridden temporarily in
plotly.io.show
:Registering new renderers
Users or third-party-libraries may register new renderers by implementing a class following a TBD interface.
Backward compatibility
For backward compatibility,
plotly.offline.init_notebook_mode
andplotly.offline.iplot
will stay around, but they will be implemented on top of the new renderer framework.For plotly.py v3 the default renderer will be
plotly_mimetype
andiplot
will callplotly.io.show
. Callingplotly.offline.init_notebook_mode()
will set the default renderer to'plotly_mimetype+notebook'
andplotly.offline.init_notebook_mode(connected=True)
will set the default renderer to'plotly_mimetype+notebook_connected'.
cc @nicolaskruchten @chriddyp @jackparmer
The text was updated successfully, but these errors were encountered: