Not able to display altair charts in jupyter notebook - python

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.

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')

If it works in one notebook and not another, there are a couple possibilities for what is going on:
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.
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.
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.

Related

Jupyter notebook renders text instead of ipywidgets

My Jupyter notebook is displaying text rather than ipywidgets. Here is a screenshot:
I read several posts about similar problems, like this one:
Jupyter Notebook not rendering ipywidgets.
Most of them indicate that the solution is to enable an extension, e.g: https://stackoverflow.com/a/38001920/11692496
But it seems to apply to older version of jupyter notebooks. I tried it anyway (with the --sys-prefix argument, which is required for virtualenv), but it didn't fix it.
I'm working with a jupyter notebook and a virtualenv. Just to be sure, I created a fresh venv and installed the minimal packages. No luck.
I'm using Python 3.10.6 and here is my versions list:
Thanks for your help!
For the record, I didn't manage to solve this issue on my virtualenv.
As #Wayne suggested above, I went for a workaround, namely a docker container based on jupyter/tensorflow-notebook

Visual Studio Code freezes after short while "The window is not responding"

Problem:
I can open VS code and start typing but after ~30s (sometimes minutes) the window freezes showing this message:
I am using python on a jupyter notebook with only a couple of unspectacular lines which I don't show because I tried different content. Last time it crashed after about 2 min of just import pandas as pd, df = pd.read_csv(path_to_file), print(df)
I think it does not crash when I don't start typing but just wait, at least not as fast
Yesterday everything was still fine. Today with the same setup not.
System information:
Windows 11 home
The only VS extensions installed are
Python v2022.7.11331006
Pylance v2022.5.1
Jupyter v2022.5.1001351004
Jupyter Keymap v1.0.0
Jupyter Notebook Renderers
Which other information is needed to help?
Attempts (not resolving the problem):
Work from a different folder with a new file/code
Disabling extensions (but notebook will not work without some)
Uninstall/reinstall same version (x64-1.67.1)
Uninstall/install previous version (1.66.1)
Unistall/install insider version (x64-1.68.0-insider)
Disable all online connecting services in VS, disconnecting from internet.
Rollback of last windows patch update
Delete backup folders in %AppData%/Code/..
Graphic card is up-to-date
I am reluctant to disable stuff that makes the dell xps faster (and expensive)
This is caused by the latest Pylance extension. You can revert to earlier Pylance extension to solve the problem. This problem will be fixed in a new version in a few days according to the github.

How to git rid of extra "|" from latex in python Jupyter notebook markdown [duplicate]

I installed IPython / Jupyter using pip on a new machine (Macbook Air with El Capitan). In a fairly simple notebook of mine (created with the same version of the whole stack) all equations, inline or not, suddenly have a vertical line on the right hand side; same height as the embedded image.
This is the case even for a single inline symbol such as $x$. I have no complicated macros or any weird LaTeX hacking going on.
Does anybody know this?
Here's a picture.
This is a change in Chrome, affecting MathJax 2.5, which ships with Jupyter Notebook 4.1. Notebook 4.2 will bundle MathJax 2.6, which will fix this problem. In the meantime, you can tell the notebook to use latest MathJax from the CDN, by adding to ~/.jupyter/jupyter_notebook_config.py:
c.NotebookApp.mathjax_url = "https://cdn.mathjax.org/mathjax/latest/MathJax.js"
Other browsers do not appear to be affected.

Python, Spyder IDE - matplotlib does not plot

I'm using:
Python 2.7.3
matplotlib 1.4.1
Spyder IDE 2.3.8
My code has to produce a chart (combination of bar and scatter) . First run on the code succeeds in that, however all following executions (both run or debug) produce just an empty chart with correct grid, label, and legend, but no bars not scatter plot. I have to close Python console and open a new one to get the correct plot, and then the story repeats. In debugger I can see that all the data for the chart is fine.
I also tried Wing IDE (ver 5.1.10-1), and the very same code works fine all the time.
I found some suggestions about setting console preferences in Spyder (ie set GUI backend to Qt4Agg, agg, TkAgg, MAcOSX, Inline and such - none of those had any effect)
I would appreciate any help with this, as I'd prefer to use Spyder.
Many thanks
P.S. I used an earlier version of matplotlib without any issues, but recently I had to update it to ver 1.4.1 to use some libraries in an unrelated software project.

Sync Jupyter notebook with Python session

I'm starting to use Python and Jupyter notebook for data analysis. I like Jupyter notebook but I sometimes prefers to use Spyder to have a quick look at the objets saved in memory (variables, dataframes, ...)
That's why I'd like to know if it's possible to have a shared
workspace between a Python session open in an IDE (like Spyder or Rodeo) and a notebook, so I can share object and avoid executing the same code twice to have the best of both world.
At least in theory, Spyder supports connecting to an external IPython kernel (e.g. one managed by Jupyter Notebook) via the "Connect to existing kernel" option: https://pythonhosted.org/spyder/ipythonconsole.html
The connection info for that can be obtained as described in http://jupyter-notebook.readthedocs.io/en/latest/examples/Notebook/Connecting%20with%20the%20Qt%20Console.html#Manual-connection
Unfortunately, that isn't actually working for me with Fedora 24's Spyder (2.3.9) and IPython (3.2.1), so I'm marking this answer as Community Wiki.

Categories

Resources