Giter Site home page Giter Site logo

Comments (9)

etpinard avatar etpinard commented on May 4, 2024

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.

arsenovic avatar arsenovic commented on May 4, 2024

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.

etpinard avatar etpinard commented on May 4, 2024

Oh ok!

Thank you for the suggestions.

Personally, I like the idea.

@theengineear @chriddyp what do you think?

from plotly.py.

theengineear avatar theengineear commented on May 4, 2024

@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.

arsenovic avatar arsenovic commented on May 4, 2024

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.

chriddyp avatar chriddyp commented on May 4, 2024

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.

arsenovic avatar arsenovic commented on May 4, 2024

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.

chriddyp avatar chriddyp commented on May 4, 2024

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.

arsenovic avatar arsenovic commented on May 4, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.