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

can't save to png with a BytesIO buffer #1381

Closed
jxrossel opened this issue Apr 27, 2017 · 9 comments · Fixed by #1560
Closed

can't save to png with a BytesIO buffer #1381

jxrossel opened this issue Apr 27, 2017 · 9 comments · Fixed by #1560
Assignees
Milestone

Comments

@jxrossel
Copy link

Hi,

I'm trying to save a Holoviews figure to png, but I fall on a bug. In plotting.renderer.save, line 477 handles BytesIO as filename, but line 469 doesn't (tries to combine the filename with '.html': self_or_cls.export_widgets(plot, basename+'.html', fmt)).

Holoviews version 1.7.0

@jlstevens
Copy link
Contributor

Thanks for reporting this.

Which Python version are you using?

@jxrossel
Copy link
Author

3.5.3

@philippjfr
Copy link
Member

Thanks for reporting this, I think what's happening here is that you're trying to save a HoloMap or DynamicMap, which ends up creating widgets which get exported in an HTML. Could you provide more detail about the object you're trying to save? I still think export_widgets should accept BytesIO but I'm not sure that's actually your intention here.

@jxrossel
Copy link
Author

Probably not, I am new to holoviews. I'll post more details tomorrow. Thanks for being proactive!

@jlstevens
Copy link
Contributor

At the very least we should generate better exceptions when trying to export objects that might have trouble exporting.

@jlstevens jlstevens added this to the v1.7.1 milestone Apr 27, 2017
@jxrossel
Copy link
Author

@philippjfr

Hi, yes indeed I was creating a HoloMap and that was the problem. To give some context, I am implementing a Django website which will display some interactive plots and also export them as png or pdf. I am (was?) hoping to avoid coding the plots twice (in bokeh - for interactivity - and matplotlib - for exportation) using Holoviews as a frontend. I see now that rendering is quite different in both so I am not sure if that's worth it anymore.

I take this opportunity to give some feedback on the documentation (if you're interested):

  • installation: for those who don't want to use iPython (or a notebook), but want to embed the bokeh result into a website, one should mention the dependence on jquery and various css / js files distributed with the library
  • for the same use-case, it took me a while to figure out how to initialize the renderers without triggering iPython-related errors (i.e. one must use import holoviews.plotting.bokeh for bokeh instead of hv.notebook_extension('...'))
  • I found out a bit by chance that hv.Store.renderers['bokeh'].instance()( hobj )[0] returns the html I needed

Not knowing where to ask this, why not here...

  • Is it possible to access the figure as a bokeh or matplotlib figure before rendering it as html or png ? (i.e. if you imagine a conversion like Holoviews -> matplotlib -> png, I'd like to get the intermediate state)
  • I have tried everything I could think of to change the bokeh figure dimension (in python) without success. Why is this wrong: hv.Curve(list(range(10)))(plot=dict(width=600,height=300)) ?
  • Is it possible to add url links in figures ?
  • In the example of the docs (http://holoviews.org/Tutorials/Columnar_Data.html >> Working with complex data), is it possible to add markers and colors which are cycled to avoid confusion when reading the legend ?

Any help much appreciated!

@philippjfr
Copy link
Member

Thanks for the detailed feedback, it's incredibly useful. I'll go through it step by step both to answer your questions and for us to figure out how to better document the various issues.

The first three points would be well addressed by a tutorial about working with holoviews outside of the notebook and some documentation about working with renderers and plots. I've got a few drafts of this, which need tidying up but I think we should definitely try to get that done for 1.7.1.

Is it possible to access the figure as a bokeh or matplotlib figure before rendering it as html or png ? (i.e. if you imagine a conversion like Holoviews -> matplotlib -> png, I'd like to get the intermediate state)

Yes, you can get a handle on the plotting object using the Renderer. The easiest thing to do is this:

bokeh_renderer = hv.Store.renderers['bokeh'].instance()
hvplot = bokeh_renderer.get_plot(hobj)
# You can now access the bokeh plot (or matplotlib figure by accessing hvplot.state)
hvplot.state

I have tried everything I could think of to change the bokeh figure dimension (in python) without success. Why is this wrong: hv.Curve(list(range(10)))(plot=dict(width=600,height=300)) ?

That's odd, definitely looks correct to me. I'll try it shortly.

Is it possible to add url links in figures ?

What do you mean by this?

is it possible to add markers and colors which are cycled to avoid confusion when reading the legend ?

Yes, simply declare Cycle objects:

markers = hv.Cycle(values=['square', 'triangle', 'circle'])
hv.NdOverlay({i: hv.Points(np.random.rand(10,2)) for i in range(3)})(style={'Points': dict(marker=markers)})

@jlstevens
Copy link
Contributor

jlstevens commented Apr 28, 2017

To re-iterate what Philipp said, thanks for the feedback!

I've got a few drafts of this, which need tidying up but I think we should definitely try to get that done for 1.7.1.

In that case, please add it to the issue with the 1.7.1 TODO list.

Is it possible to add url links in figures ?

I think this means adding clickable links in the figure itself (e.g the figure title). I believe I've seen matplotlib examples of this in the past but haven't encountered this idea since.

@jxrossel
Copy link
Author

Thank you so much for these answers! I'll check them out asap.

For the URL thing, I'd like to allow the user to click on a point / line / label to reach another page, as described here:
http://bokeh.pydata.org/en/latest/docs/user_guide/interaction/callbacks.html#openurl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants