Sagar
Sagar

Reputation: 283

Not able to display altair charts in jupyter notebook

I am not able to display the charts on jupyter notebook. The same code displays on chrome in one laptop but does not work on chrome on other laptop.

I do not see any error or even a empty plot when I execute the code but get alt.Chart(...) in the output.

The version of altair and vega etc are same on both the laptops.

Upvotes: 2

Views: 5896

Answers (2)

archangel
archangel

Reputation: 31

For 'altair' version of '4.1.0', 'vega' version of '3.4.0' just do alt.renderers.enable('default') instead of alt.renderers.enable('notebook')

Upvotes: 3

jakevdp
jakevdp

Reputation: 86300

If it works in one notebook and not another, there are a couple possibilities for what is going on:

  1. your notebooks are connected to different kernels with different versions of Altair and/or its dependencies installed. Run the following

    import sys
    print(sys.executable)
    

    to see if you're using the same Python executable in your environments. If the results are different, you can use Kernel -> Change Kernel in the Jupyter notebook menu to change to a kernel with a working Altair version.

  2. If that's not the case, then it is likely that you have inadvertently enabled a different renderer in one of the notebooks, for example by running alt.renderers.enable('notebook'). In Altair 4.0, the default renderer should work out-of-the-box in both Jupyter notebook and JupyterLab. Either restart your kernel or run alt.renderers.enable('default') to restore the default.

  3. The behavior above can happen if you have too old a version of IPython installed. See If the notebook displays on one laptop and not the other, it may be that the broken one has too old a version of IPython installed. See https://altair-viz.github.io/user_guide/troubleshooting.html#notebook-textual-chart-representation for more information on what to upgrade.

See Altair's Display Troubleshooting guide for more information.

Upvotes: 1

Related Questions