question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow passing of plotly / iplot parameters into OrbitPlotter3D()

See original GitHub issue

It would be useful to be able to pass plotly iplot function parameters when calling OrbitPlotter3D():

#/via https://plot.ly/python/offline/

#Help on function iplot in module plotly.offline.offline:

iplot(figure_or_data,
      show_link=True,
      link_text='Export to plot.ly',
      validate=True,
      image=None, 
      filename='plot_image',
      image_width=800,
      image_height=600)

This would allow control over things like the display of the link to plotly (show_link), the image type used when grabbing and downloading a snapshot of the current orientation of a 3D plot (image) and the filename it is saved with (filename).

At the moment, no parameters are passed into iplot().

From https://github.com/poliastro/poliastro/blob/master/src/poliastro/plotting.py:

def show(self, **layout_kwargs):
        """Shows the plot in the Notebook.
        """
        self._prepare_plot(**layout_kwargs)

        iplot(self.figure)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
astrojuanlucommented, Sep 23, 2018

+1 on renaming _prepare_plot to style_plot and keep everything the same!

def style_plot(self, **layout_kwargs):
    """Changes the style of the plot.
    """
    # If there are no orbits, draw only the attractor
    if not self._data:
        self._redraw_attractor()

    if layout_kwargs:
        self._layout.update(layout_kwargs)

def show(self, **layout_kwargs):
    """Shows the plot in the Notebook.
    """
    ...

Note: This code is incomplete because show should have **iplot_kwargs instead, see comments below.

The interesting part is adding a test for it. Do you want to give it a try?

1reaction
psychemediacommented, Sep 21, 2018

@Juanlu001 Re: options.

I’d considered allowing options in to OrbitPlotter*D but it feels to me that that’s too early to commit to the iplot. It would mean the output parameters are required before you build up the plot, rather than just as you are about to plot it, and they are hanging around all the way through the plotting process?

If _prepare_plot() was public then how would it work? Maybe rename it as style_plot(), becuase that feels more explicit?

def style_plot(self, **layout_kwargs):
        """Style the plot.
        """
        if layout_kwargs:
            self._layout.update(layout_kwargs)

def show(self, **iplot_kwargs):
        """Shows the plot in the Notebook.
              Optionally allows the iplot widget to be customised.
        """
        # If there are no orbits, draw only the attractor
        if not self._data:
            self._redraw_attractor()

        #Plot the figure
        iplot(self.figure, **iplot_kwargs)
#---
...
#and then the user does something like:
frame.style_plot(...) #optionally
frame.show(show_link=False)
...

That feels reasonably natural? (I’m also assuming that self._redraw_attractor() and self._layout() are independent on each other and have no side-effects either way?)

How would making the layout property public work? What commands would folk be running where? Maybe:

frame.layout.update(...)
frame.show(show_link=False)

This would require some checking for references to _layout elsewhere; for consistency, but then should _layout in other classes have to go public too? Maybe this has too many side-effects?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Plotly express arguments in Python
Arguments can either be passed as dataframe columns, or as column names if the data_frame argument is provided. Passing columns as arguments¶. In...
Read more >
Configuration in Python - Plotly
You can set the configuration options for your figure by passing a dictionary to this parameter which contains the options you want to...
Read more >
Plotly express wide-form support in Python
Over 26 examples of Plotly Express Wide-Form Support including changing color, size, log axes, and more in Python.
Read more >
plotly.graph_objects.Figure — 5.11.0 documentation
A dict of string/value properties that will be passed to the Layout constructor ... or allows those events to pass through to data...
Read more >
Creating and updating figures in Python - Plotly
add_trace() etc) as described below. Graph object constructors and update methods accept "magic underscores" (e.g. go.Figure(layout_title_text="The Title") ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found