Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

is alt.renderers.enable('altair_saver', ['vega-lite', 'png']) on README outdated? #76

Closed
zyxue opened this issue Sep 3, 2020 · 10 comments

Comments

@zyxue
Copy link

zyxue commented Sep 3, 2020

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-53-092c93936f9f> in <module>
----> 1 altair.renderers.enable('altair_saver', ['vega-lite', 'png'])

TypeError: enable() takes from 1 to 2 positional arguments but 3 were given

https://github.com/altair-viz/altair/blob/582b590a29dfbfc06aad27be79371f98a763a0aa/altair/utils/plugin_registry.py#L156

@zyxue zyxue changed the title is alt.renderers.enable('altair_saver', ['vega-lite', 'png']) on README outdate? is alt.renderers.enable('altair_saver', ['vega-lite', 'png']) on README outdated? Sep 3, 2020
@jakevdp
Copy link
Member

jakevdp commented Sep 3, 2020

Maybe it needs to be passed as a keyword argument?

@zyxue
Copy link
Author

zyxue commented Sep 3, 2020

what would the keyword be?
tried

>>> altair.renderers.enable('altair_saver', fmts=['vega-lite', 'png'])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/path/to/lib/python3.8/site-packages/altair/utils/plugin_registry.py", line 177, in enable
    return PluginEnabler(self, name, **options)
  File "/path/to/lib/python3.8/site-packages/altair/utils/plugin_registry.py", line 27, in __init__
    self.registry._enable(name, **options)
  File "/path/to/lib/python3.8/site-packages/altair/utils/plugin_registry.py", line 142, in _enable
    ep = entrypoints.get_single(self.entry_point_group, name)
  File "/path/to/lib/python3.8/site-packages/entrypoints.py", line 217, in get_single
    raise NoSuchEntryPoint(group, name)
entrypoints.NoSuchEntryPoint: No 'altair_saver' entry point found in group 'altair.vegalite.v4.renderer'

@jakevdp
Copy link
Member

jakevdp commented Sep 3, 2020

The NoSuchEntryPoint error suggests that the altair_saver package is not installed in the environment where you're trying to use it.

@zyxue
Copy link
Author

zyxue commented Sep 3, 2020

I see, thanks. it's unclear what the keyword should be, and how it works. All these seem to run

>>> import altair
>>> altair.renderers.enable('altair_saver', abc=['vega-lite', 'png'])
RendererRegistry.enable('altair_saver')
>>> altair.renderers.enable('altair_saver', xyz=['vega-lite', 'png'])
RendererRegistry.enable('altair_saver')
>>> altair.renderers.enable('altair_saver', fmts=['vega-lite', 'png'])
RendererRegistry.enable('altair_saver')

@jakevdp
Copy link
Member

jakevdp commented Sep 3, 2020

I think fmts is the correct argument. I suspect the others will fail when you try displaying a chart.

@zyxue
Copy link
Author

zyxue commented Sep 3, 2020

I see. you're right.

Is

altair.renderers.enable('altair_saver', fmts=['svg'])

the same as

altair.renderers.enable('svg`)

?

Both seem to work

@jakevdp
Copy link
Member

jakevdp commented Sep 3, 2020

Yes, they do the same thing. altair_saver provides a superset of the functionality of altair's built-in renderers.

@jakevdp
Copy link
Member

jakevdp commented Sep 3, 2020

(and under the hood, altair.renderers.enable('svg') is using altair_saver)

@zyxue
Copy link
Author

zyxue commented Sep 4, 2020

I find it a bit confusing. How could I better understand it given that altair_saver is the name of a saver while svg is the name of a format? How is it structured under the hood?

@jakevdp
Copy link
Member

jakevdp commented Sep 4, 2020

In order to display a chart as SVG, it has to first be saved to SVG in memory.

@zyxue zyxue closed this as completed Sep 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants