-
-
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
New module proposal: plotly.io #1098
Comments
Big +1 for the high-level goals and the initiative. The API looks fine to me in principle as well :) I love the harmonization of all of these things. |
👍 from me too. Love everything about this. Could really clear up a major source of confusion for Plotly's Python library users. Would love to see a parallel issue for documentation updates.
We should definitely be shooting for this 🌠 - the last frontier for eclipsing some of the legacy technical computing chart libraries 🌑 |
@jackparmer, two closely related documentation issues are:
It will help a lot if we can work out a way to release the docs for each (minor) version. This way the docs don't have to be backwards compatible, and we can update them to reflect the current best practices of each version. If we make progress on the |
wouldn't minor versions be backwards compatible? |
@cldougl I would like to be able to update the docs with each version to reflect the current recommended way to do things, even if the current recommended way didn't exist in the last minor version. Does that make sense? |
The beginning of the So I'm going to remove the 3.2.0 milestone, but leave the issue open until all of our legacy I/O functionality is reproduced in this module. |
Done in #1474 |
hello: the whole day i am trying to find the solution with no result i did all what you said concerning the iplot pip conda list uninstall and reinstall with no result. now i have a new error FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\33788\Anaconda3\lib\site-packages\plotly\package_data\templates\plotly.json' i think that i have to install plotly in a specific place but how to do i don't know |
Overview
I propose that we introduce a new module,
plotly.io
, to house a new suite of functions related to the input and output of plotly figure objects.Why now?
There are two immediate needs motivating this proposal.
How do things work now?
Here's in inventory of some of our current methods that can perform I/O operations:
plotly.plotly.plot
plotly.offline.plot
div
stringplotly.image.save_as
plotly.get_figure
Why add something new?
By my taste, these APIs are a bit scattered and not very discoverable by users without consulting external documentation. It's also unclear (to me at least) where additional I/O methods, like to two listed above, should be added.
There are good reasons that we ended up where we are (e.g. there was no offline mode when the
plotly.plotly
module was developed), but I'd like to propose we adopt a new approach moving forward.The goal is that the options for saving/loading/converting figures should consistent and easily discoverable without the need to consult external documentation. By triggering tab-completion on the
plotly.io
module, users should be able to learn about all of the import/export options available to them.Design
I propose that the initial functions in the
plotly.io
module have one of 4 prefixes, followed by the format name:read_{format}(file, ...) -> Figure
: These methods all accept, as the first argument, either a string or aread
-able file object. Strings are interpreted as local file paths, other objects are read from. These methods all return aFigure
object.write_{format}(fig, file, ...) -> None
: These methods all accept theFigure
to be written as the first argument. The second argument is either a string or awrite
-able file object. Strings are interpreted as local file paths, other objects are written to. These methodsraise
on write failures and returnNone
.from_{format}(data, ...) -> Figure
: These methods all accept, as the first argument, some in-memory Python object and return aFigure
object. These methods don't interact with the file system and have no side effects.to_{format}(fig, ...) -> Any
: These methods all accept theFigure
to be converted as the first argument. They return an in memory Python object corresponding to the format. These methods don't interact with the file system and have no side effects.The ellipses (
...
) in the signatures above represent additional arguments/options that are specific to given format.In addition to their presence as standalone functions in
plotly.io
, there would also bewrite_{format}
andto_{format}
methods onFigure
objects. This way, people could use tab completion on a figure itself to learn how to save/convert it.Examples
Here are some examples of functions that could follow these conventions
Save to HTML file and embed plotly.js
Build an HTML
div
string for figure, and don't embed plotly.jsSave figure to a file as an svg image of a specific size (using orca)
Build a bytes string representation of the Figure converted to a PNG image
Build a
PIL
Image
object representing the figure as a static imageSave to json file
Save as gzipped json file to an HDFS filesystem using PyArrow
Convert to json string
Convert figure to plot.ly url
Get figure from plot.ly url
Convert matplotlib/altair/holoviews/other object to plotly figure
What happens to
plot
?Nothing, it works fine and there's no reason to change it. Some of these new methods could directly call the current plot methods, or we could look at refactoring the internals a bit so that both
plot
andio
methods share most of their logic.What about displaying plots?
I don't intend for any of the
to_{format}
/save_{format}
functions to display the figure. So initially, theplot
andiplot
methods would continue to serve that purpose.One option would be to eventually add a
plotly.io.show
method that is capable of displaying figures using different "backends" (similar in spirit to matplotlib). We actually already have 5 backends for displaying figures:plotly.plotly.plot
)plotly.plotly.iplot
)plotly.offline.plot
)plotly.offline.iplot
)plotly.graph_objs.FigureWidget
)Once we have orca integrated, we could even add a static image backend if people were interested in that.
Milestone
I propose adding the
plotly.io
module with support for json and orca-based image formats in version 3.2.0. Depending on how much work it turns out to be, it would be nice to also populate the module with existing html and plot_ly support as well.Please chime in if you have opinions on this!
cc: @chriddyp @cldougl @Kully @nicolaskruchten @jackparmer @bcdunbar
The text was updated successfully, but these errors were encountered: