Some Plotly plots not showing in JupyterLab - python

I have successfully installed the Plotly python libraries to work with JupyterLab. I have the proper extensions installed. (All directions were followed according to: https://plot.ly/python/getting-started/ )
Most basic plots show up in my notebook file just fine, with interactivity working great! However, some plots are not appearing, and I have no idea why.
For example, the following works just fine:
import plotly.express as px
df = px.data.iris()
fig = px.scatter(df, x="sepal_width", y="sepal_length",
color="species", marginal_y="rug", marginal_x="histogram")
fig.show()
However, a simple scatter_matrix or parallel_coordinates shows no output. For example, the following does not work:
fig = px.scatter_matrix(df, color="species")
fig.show()
No errors appear on the console or in the output cell. The cell executes, and that's it. It doesn't show any result.
I did the following:
Updating conda: conda update --all -c plotly -c conda-forge
Cleaning and rebuilding jupyter lab extensions: jupyter lab clean and jupyter lab build.
I also tried the relevant troubleshooting options according to: https://plot.ly/python/troubleshooting/.
I tried running the notebook in regular Jupyter, and it doesn't work there either, though the start of a plot does appear, with a sad face on the plot, indicating that something is not happy, but I'm not sure what.
I tried recoding the above using the plotly.graph_objects API instead of plotly.express. Same outcome.
I still have the same problems.
It's worth noting that I CAN do the following:
fig = px.scatter_matrix(df, color="species")
fig.show(renderer='browser')
And that automatically opens the browser window and works just fine. So, it seems that the plotly engine itself is fine, there is just something up with the jupyter connection for some types of plots.
Any suggestions on where to look, or what I'm doing wrong? Thank you!

Well, after trying out a lot of different things to get this working, I finally went back and decided to just clean everything up. I did the following:
conda clean --all
conda update --all -c plotly -c defaults -c conda-forge (The order of the channel specifiers is important!)
jupyter labextension update --all
jupyter lab clean
jupyter lab build
And, I also noticed that my notebook was not trusted. So, I made the notebook trusted. And, now everything is working! There were MANY updates when I did conda update --all above because of the order that I used with the channels. I definitely put the defaults channel as higher priority, with left far fewer packages installed from conda-forge. This changed the version of a lot of packages, but I'm not certain which ones. I could look through the revisions in conda and get that list later, though packages are always being updated, so it might not be relevant.
I wondered if it was possible that setting the notebook to trusted was really the only problem? Well, I tried to clear the trust setting:
jupyter trust --reset
And, it still worked. So, I'm inclined to believe that it was not a trust issue with the notebook, but some version conflict with the numerous packages that I updated from the main conda channel defaults instead of conda-forge.
For the moment, all is well. Thanks, rpanai for chiming in.

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

`ipywidgets.interact` shows the widget itself but does not apply the function in the argument (Jupyter Notebook)

I have a problem that interactive objects from ipywidgets do not work in Jupyter Notebook on my computer. The widget itself is displayed but the function that it should control (e.g. drawing graph with changing parameter), seemingly, does not run. I took example from documentation and it does not work.
The picture of code and output
Code:
import ipywidgets
import widgetsnbextension
def greeting(text="World"):
print("Hello {}".format(text))
ipywidgets.interact(greeting, text="IPython Widgets")
What have I already tried:
There were similar questions, like this but the answer didn't work for me (the answer was to run this:
jupyter nbextension enable --py widgetsnbextension).
The code above works in GoogleColab so I tried to install their versions of packages ipython and ipykernel (packages ipywidgets and widgetsnbextensions were of the same version as mine). But it has led to errors so I have given up this idea. I have the latest versions of all packages now and I don't have Anaconda.
What should I try next? May be I am wrong and the problem has a different cause?
I found the answer!!!
I have had several nbextensions switched on (see screenshot). This was my mistake to include everything which seemed useful. When I turned off all nbextensions then all ipywidgets stuff started to work. Finally, I found that one particular extension called Limit Output is to be blamed for. Turn it off and all works fine.
The moral: don't use everything if you don't need it. Also, obviously, there is a bug in Limit Output extension because it is not supposed to affect widgets (it is supposed to limit output data when you accidentally write while(true) or something like that).
You can read some useful stuff about SageMath in the comments under the original question as well.

How can I make the Lux package work in Python?

I was trying to use the package called LUX for Python. I followed this tutorial. So it was pretty simple, I just had to import some csv and when I called my data, I would be able to see multiple graphs. The problem is that I do everything and nothing shows up for me.
I was using Melbourne House Market data, and this is my script so far:
# firstly, we install package and extensions
!pip install lux-api
!jupyter nbextension install --py luxwidget
!jupyter nbextension enable --py luxwidget
# then, load the packages
import lux
import pandas as pd
# load data
melb_data = pd.read_csv("melb_data.csv")
So far so good... at least, I thought so. After doing these things, when we see the tutorial mentioned in the begining of this question, it mentions that if we call the dataframe now, instead of appearing only the dataset, we would be able to see some graphics as well. But that didn't happen to me. I know screenshots are not the best choice, but this is what I see:
As you can see, there is the Toggle button, but it is only working to hide the table. there isn't the graphs I saw in the tutorial. I also tried to follow this tutorial as well, but there isn't anything new there.
Any ideas on what I'm missing here? Why I can't find a way to make this package work?
It seems that you have not installed the JuypterLab extension. It is described in the README file that you linked, here. You will need to execute the following two commands:
jupyter labextension install #jupyter-widgets/jupyterlab-manager
jupyter labextension install luxwidget
and then restart JupyterLab. The prerequisite here is having a JupyterLab 2.x or 3.x and Node.js installed (while many extensions for JupyterLab 3.x do not require node.js any longer, this one still does - as it seems).

Kernel appears to have died - Jupyter notebook python matplotlib

I am trying to learn charting in Python and keep getting this message in Jupyter:
The kernel appears to have died. It will restart automatically.
My other basic programs are working, so it looks like using Matplotlib is causing this problem. Any thoughts on how to resolve this?
import matplotlib.pyplot as plt
plt.plot()
plt.show()
if you don't solve the problem after using method above, you can try this:
import os
os.environ['KMP_DUPLICATE_LIB_OK'] = 'True'
add two lines of codes in your python code. This mothed is also useful to pycharm.
I try the solution of this video, based on this post, and it worked for me:
Run Anaconda Prompt as administrator
conda install --yes freetype=2.10.4
I did the following :
conda install --yes freetype=2.10.4
it works. Great!

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.
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.

Categories

Resources