Skip to content
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

Add top-level save and render utilities #3134

Merged
merged 20 commits into from
Nov 16, 2018
Merged

Conversation

philippjfr
Copy link
Member

@philippjfr philippjfr commented Nov 4, 2018

This PR adds top-level hv.save and hv.render utilities which we have long wanted and are much more obvious than the obscure hv.renderer(backend).save(obj, filename, fmt) and hv.renderer(backend).get_plot(obj).state APIs.

  • hv.render: Renders the holoviews object to the representation in of the backend, e.g. for bokeh returns bokeh Figure objects. This is very useful for incorporating HoloViews into a workflow where you're working directly with the underlying library but want to take advantage of some plot type that's only provided by HoloViews.

  • hv.save: Convenient API for saving holoviews objects to any format, including png, svg, gif, mp4, and both scrubber and selection widgets.

Here is a notebook demonstrating what the API looks like in practice (note that because of the way exported HTML files are embedded some of the widget examples do not work but will work when working with the exported file directly).

  • Add documentation

@philippjfr
Copy link
Member Author

If anyone has suggestions on where to document these that would be very helpful.

Copy link
Member

@jbednar jbednar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really useful! I have wanted something like this for a long time, but never took the time to write it, so I am very glad you did.

The available output formats available depend on the backend being
used. By default and if the filename is a string the output format
will be inferred from the file extension. Otherwise an explicit
format will be specified. For ambiguous file extensions such as
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will need to be specified?

holoviews/util/__init__.py Show resolved Hide resolved
will be inferred from the file extension. Otherwise an explicit
format will be specified. For ambiguous file extensions such as
html it may be necessary to specify an explicit fmt to override
the default.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That last bit is confusing to me -- what fmt other than 'html' would be more explicit? If you mean widgets vs. scrubber, please say that explicitly -- i.e. that .html will by default be XX, but if you don't want that, specify YY.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.


def render(obj, backend=None, **kwargs):
"""
Renders the object to a figure object.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renders the HoloViews object to the corresponding object in the specified backend, e.g. a Matplotlib or Bokeh figure.

The backend defaults to the currently declared default backend. The resulting object can then be used with other objects in the specified backend. For instance, if you want to make a multi-part Bokeh figure using a plot type only available in HoloViews, you can use this function to return a Bokeh figure that you can use like any hand-constructed Bokeh figure in a Bokeh layout.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

@philippjfr
Copy link
Member Author

Just noticed all the +1's on this issue: #1819 Adding this is really overdue. I'll try to add this to the getting started and user guides in the appropriate places.

if fmt == 'auto' and formats and formats[-1] != 'html':
fmt = formats[-1]
if formats[-1] in supported:
filename = '.'.join(formats[:-1])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if the format isn't supported?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renderer.save automatically adds the file extension no matter what file extension you supply (which I've found pretty annoying tbh). So if you don't supply a file extension it'll pick whatever the default is.

@jlstevens
Copy link
Contributor

I am happy with these utilities and I do think they are useful. I'm not entirely sure where in the docs this should go though I think save can be mentioned early on in our current exporting and archiving user guide.

Maybe render can be the first thing in 'Working with Plots and Renderers' though it would be nice to mention it earlier. Maybe at the first point where we show multiple backend support?

Happy to merge the code now for a subsequent docs PR or wait for that material to be added here.

@jbednar
Copy link
Member

jbednar commented Nov 8, 2018

Wherever render is mentioned, please also mention finalize_hooks, because I think many of the things people think they need render for can be done more cleanly using finalize_hooks, allowing them to spend more of their time in the HV world instead of leaving it to start working with Bokeh directly (except where strictly necessary, using finalize_hooks).

@philippjfr
Copy link
Member Author

philippjfr commented Nov 8, 2018

I know we've already gone through the whole finalize_hooks vs. final_hooks mess, but how do you feel about renaming finalize_hooks to just hooks (with a proper deprecation cycle of course)? Initially we had considered adding initial_hooks but there is effectively no use for them and the current name is quite annoying to type out.

@philippjfr
Copy link
Member Author

I am happy with these utilities and I do think they are useful. I'm not entirely sure where in the docs this should go though I think save can be mentioned early on in our current exporting and archiving user guide.

I think this is probably way to deep into the material, I'd like at least a mention in getting started section and I'll also add FAQ items.

@philippjfr
Copy link
Member Author

I've overhauled the FAQ a bit with sections for save and render/finalize_hooks (also applied some unrelated edits). Will look at the getting started and user guides next.

@philippjfr
Copy link
Member Author

@jlstevens @jbednar Ready for another round of review, here's what I've done for documentation:

  • FAQ items about hv.save and hv.render separately
  • Very short entry about hv.save in Getting Started Introduction
  • Mentioned hv.save as alternative to %%output filename=... in Exporting user guide
  • Detailed description of hv.render and finalize_hooks in Plots and Renderers.

@philippjfr
Copy link
Member Author

I've now also aliased finalize_hooks to hooks and marked this PR with deprecated to make sure that when we write up the release notes the deprecation of finalize_hooks is mentioned.

Copy link
Member

@jbednar jbednar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks! My wording suggestions are minor, and if any of them are not accurate, please disregard them but try to clarify it in the correct direction instead.

doc/FAQ.rst Outdated Show resolved Hide resolved
doc/FAQ.rst Outdated Show resolved Hide resolved
doc/FAQ.rst Show resolved Hide resolved
doc/FAQ.rst Outdated Show resolved Hide resolved
doc/FAQ.rst Outdated Show resolved Hide resolved
examples/user_guide/Plots_and_Renderers.ipynb Outdated Show resolved Hide resolved
holoviews/plotting/bokeh/plot.py Outdated Show resolved Hide resolved
holoviews/plotting/bokeh/tabular.py Outdated Show resolved Hide resolved
holoviews/plotting/mpl/plot.py Outdated Show resolved Hide resolved
holoviews/util/__init__.py Show resolved Hide resolved
jbednar and others added 4 commits November 9, 2018 23:17
Co-Authored-By: philippjfr <[email protected]>
Co-Authored-By: philippjfr <[email protected]>
Co-Authored-By: philippjfr <[email protected]>
Co-Authored-By: philippjfr <[email protected]>
@philippjfr
Copy link
Member Author

Review comments now addressed, ready to merge.

@philippjfr
Copy link
Member Author

@jlstevens Please review and merge this.

@jlstevens
Copy link
Contributor

Looks good. Merging.

@jlstevens jlstevens merged commit 6f505a1 into master Nov 16, 2018
@philippjfr philippjfr deleted the save_render_utilities branch December 13, 2018 04:22
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants