-
-
Notifications
You must be signed in to change notification settings - Fork 404
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
Conversation
980f335
to
08eb817
Compare
If anyone has suggestions on where to document these that would be very helpful. |
There was a problem hiding this 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.
holoviews/util/__init__.py
Outdated
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 |
There was a problem hiding this comment.
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
Outdated
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.
holoviews/util/__init__.py
Outdated
|
||
def render(obj, backend=None, **kwargs): | ||
""" | ||
Renders the object to a figure object. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.
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]) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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 Maybe Happy to merge the code now for a subsequent docs PR or wait for that material to be added here. |
Wherever |
I know we've already gone through the whole |
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. |
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. |
@jlstevens @jbednar Ready for another round of review, here's what I've done for documentation:
|
e494eff
to
42265df
Compare
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. |
There was a problem hiding this 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.
Co-Authored-By: philippjfr <[email protected]>
Co-Authored-By: philippjfr <[email protected]>
Co-Authored-By: philippjfr <[email protected]>
Co-Authored-By: philippjfr <[email protected]>
Co-Authored-By: philippjfr <[email protected]>
Co-Authored-By: philippjfr <[email protected]>
Co-Authored-By: philippjfr <[email protected]>
Co-Authored-By: philippjfr <[email protected]>
Co-Authored-By: philippjfr <[email protected]>
Co-Authored-By: philippjfr <[email protected]>
Co-Authored-By: philippjfr <[email protected]>
Co-Authored-By: philippjfr <[email protected]>
Review comments now addressed, ready to merge. |
@jlstevens Please review and merge this. |
Looks good. Merging. |
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. |
This PR adds top-level
hv.save
andhv.render
utilities which we have long wanted and are much more obvious than the obscurehv.renderer(backend).save(obj, filename, fmt)
andhv.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).