Comments (9)
Try
import plotly.plotly as py
import matplotlib.pyplot as plt
# your matplotlib functions
# ...
mpl_fig = plt.gcf()
py.iplot_mpl(mpl_fig, filename='plotly_fig-from-mpl_fig')
Let me know if the above does not yield what you had in mind.
Cheers.
from plotly.py.
so this works, but you dont want to do that for every plot.
the enable_notebook(), is good for ipython notebook, because it wont change your workflow
also it would be cool if iplot_mpl
did gcf()
by default (ie with no arguments)
from plotly.py.
Oh ok!
Thank you for the suggestions.
Personally, I like the idea.
@theengineear @chriddyp what do you think?
from plotly.py.
@arsenovic, I'm on the fence for this change. Mostly because I think it promotes adding figures to ones Plotly account in an unchecked fashion.
The latter suggestion, to just infer with gcf()
is interesting. It still shifts the responsibility to the user to properly name figures, but enables the user to have a complete copy-and-paste solution.
In other words, it'd probably be better to do this:
py.iplot_mpl(filename='working-plot')
But we understand if you want to do this:
py.iplot_mpl()
However, I sort of feel like adding this feature is only a marginal gain over doing this, which should currently work, and is not specific to any mpl figure:
py.iplot_mpl(gcf())
Again, @etpinard, @chriddyp, thoughts?
from plotly.py.
i agree, that any solution has to scalable. ipython notebook plots are deleted when the cell is deleted, im not sure how to make this feature continuous with plotly's cloud file-system. maybe ipython notebook has some kind of hook, or could implement one.
but this raises a larger issue. ..
i would argue that ripping out plots without thinking about where they are going is a great feature of ipython, and a necessary one if you intend to support the exploratory computing model.
the question then becomes is plotly supposed to be used for this? or is plotly something you use when you are done and want to publish/share your plot?
from plotly.py.
Thanks for the suggestion! Still not quite clear to me what the suggested behaviour would be. Is it:
# Cell 1
...
plt.gcf()
# Cell 2
...
plt.gcf()
# Cell n
...
plt.gcf()
# Cell n+1
# Now convert all of the above figures to plotly
plotly.convert_notebook()
Or is it something like
# Cell 1
plotly.convert_notebook()
# Cell 2
plt.gcf() # returns and embeds a plotly figure, instead of a matplotlib figure
?
from plotly.py.
so if you look just above this section in the mpld3 example, you will see that he can turn on note-book wide mpl->mpld3 conversion.
so the idea is that if i put py.enable_notebook()
at the top of my existing notebooks, then the will all run and all the plots will be plotly.
https://github.com/jakevdp/mpld3/blob/master/mpld3/_display.py#L357-L405
from plotly.py.
Ah I see. Perhaps we'd require a filename or notebook argument to enable_notebook
that would automatically name the files for you, e.g.
py.enable_notebook(filenames='lab notebook')
plt.gcf() # saves figure to plotly with filename `lab notebook, cell #1`, embeds figure in notebook
...
plt.gcf() # saves figure to plotly with filename `lab notebook, cell #7`, embeds figure in notebook
Perhaps executing the same graph in the same cell would overwrite the same graph. This would be quite a bit easier and more organized than requiring a filename for every graph.
from plotly.py.
im not sure what the gcf() is demonstrating in your example code, but yes, ideally you would need to add cell-aware-ness to plotly, like
- re-running a cell doesnt create a new plotly-file
- deleting a cell deletes the plotly-file
because each cell can contain more than one plot, there is not a unique cell<-> plot connection.
also, maybe storing all plots of a given notebook in a folder/ would unclutter the users file-system. now that the notebook supports folders, im not sure how you would do this uniquely.
perfectly interconnecting plotly and the notebook is not a simple problem...
from plotly.py.
Related Issues (20)
- `fillgradient` doesn't work when `renderer=vscode` is used on notebook HOT 1
- Sort feature for icicle chart
- Scattergl points disappear when reaching a certain threshold in size difference HOT 5
- Parallel coordinates mixed categrical and numerical values HOT 1
- Docs: "Download as HTML" recommends using a `data:` URL, which is restricted in Dash>=2.15.0 HOT 1
- multiple Legends not working in VS code HOT 2
- px.strip jitter doesn't work as expected due to underlying go.Box config HOT 1
- The color of Scattergl points are missing when using animation HOT 1
- tickmode='sync' option is not working as intended
- Cannot provide custom HTTP headers (e.g. bearer token) to Mapbox layer source HOT 2
- `Legendrank` does not work in plotly (pyscript) when `fill` argument is used HOT 2
- Test dependency versions are out of date
- why isn't fig.update_zaxes implimented
- Hover data not displaying on plotly map HOT 1
- plotly.express.scatter_geo() function cannot generate world map HOT 1
- Plotly legends cutoff in Quarto Dashboards
- Opacity and color not working together in px.scatter HOT 1
- Clarify installation of jupyterlab-plotly extension in documentation for JupyterLab 3.x HOT 2
- Making Radar Charts: make_trace_kwargs uses df.append which has been deprecated in pandas 2.0 HOT 1
- zorder doesn't work on version 5.21.0 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plotly.py.