PyPlot figure not shown in VS Code Jupyter "UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure." - visual-studio-code

I run Julia inside Jupyter notebook within the Microsoft Visual Studio Code IDE.
When I try to make a PyPlot plot, the figure is not shown at and instead I am seeing the following message:
UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.

The figure will be shown when a PyPlot.display_figs() line will be added at the end of the cell code (note that the display_figs method is not exported so it needs be prepended with PyPlot).
Note that I observe this happening from time to time on some VS Code installation so I publish here this workaround so other people can easily google it.

Related

Why jupyter notebook or lab doesn't show an interactive pyvista scene?

I am unable to interact with pyvista plots either on jupyter notebook or lab. I am working on a geometric problem and want to check output of the code both in graphs and text (e.g., check vertex coordinates or face normals of a mesh). I get interactive Pyvista plots if I just run the code in a py script, but it is a slow workflow and have to check print() results somewhere else.
I am adding
pl.show(jupyter_backend='pythreejs')
as the pyvista documentations suggests, but I still get a static plot. It's the same problem in VS Code, where I started. I thought it might be VS Code so I installed Jupyter notebook and jupyter lab. No success. I really appreciate any help. It's frustrating to get stuck in the first step of visually checking the output in an interactive way which is necessary for solving a geometric problem, not to mention posting it later online. Appreciate any help.

Unable to load Plotly graphs from Jupyter notebook to Github

I have imported following packages in code in my Jupyter notebook and have plotted few graphs. However, when I am uploading python file on github the graphs are not showing.
I have also tried using nbviewer as suggested in some of the posts but even in nbviewer the plotly graphs are appearing blank.
Libraries imported:
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
import plotly.io as pio
from IPython.display import Image
nbviewer URL:
https://nbviewer.org/github/rj180492/Python/blob/main/Covid-19%20Impacts%20Analysis%20using%20Python.ipynb
Try:
pip install plotly
...as your first cell in the notebook and then try NBviewer. It worked for me. I was pretty sure it was working when it took several minutes for NBviewer to load the first time.
My NBviewer Example
I guess the other libraries are part of Nbviewer by default.
Curiously, my first version just had one plotly plot and it worked. Single color points though. When I got fancy and added another plot that had multiple colors, neither plot rendered. It also took hours to update. After pushing the version with pip install, NBviewer updated right away, it just took a long time to load.
Those having a related issue should note that the OP wrote in the comments below that despite it working for me via nbviewer when I ran the same notebook and posted my results on GitHub, OP had issues still. What sorted it out in that case so the plots showed up in nbviewer (yet still not in the GitHub quick-preview, which is as expected currently) was going to settings in the repository and choosing 'Pages' > 'Source' and from that dropdown selecting branch as main.
nbviewer is meant to the way to share things with other from the Jupyter ecosystem. (There are some others closely related, such as notebook{sharing}space
that is similar yet private by default because you don't need to have it on GitHub and the URLs are generated in a way others won't see unless you share publicly because of complex.) The nice thing about nbviewer is that is is meant for non-tech savvy.
Plotly should render on nbviewer and in many cases is still interactive, such as here where you can click and rotate or zoom the plots, as nbviewer will allow javascript whereas GitHub presently doesn't.
I put in comments that I wasn't seeing what you are and have linked to demonstrations.
Always only think of the GitHub page as a quick preview. See more about this here, here, here, plus there's other present deficiencies I have noted but haven't pointed to other places (text justification with Pandas dataframes, etc.). Static GitHub-notebook viewing in the browser is also not inviting for those unfamiliar with GitHub as it is embedded in an interface meant to get GitHub users to the code & not to feature the notebook content. Nbviewer does a better job featuring the content.
The method that worked for me was the following:
install these libraries:
pip install plotly cufflinks char_studio
then add these lines:
import cufflinks as cf
import chart_studio.plotly as py
import plotly.express as px
import plotly.graph_objects as go
import plotly.figure_factory as ff
import plotly.io as pio
from plotly.offline import init_notebook_mode
then
pio.renderers.default = "notebook_connected"
init_notebook_mode(connected=False)
cf.go_offline()
To be honest, I don't know why that worked, but you can see this as an example

Jupyter notebook auto indentation doesn't work for scala

I have being using jupyter notebook from the anaconda distribution for quite awhile, and I have installed both Python 2 and 3, and R kernels. They all work fine.
Recently, however, after I installed scala kernel, everything works fine except for the auto indentation, i.e. the cursor always sits at the beginning of a line after the enter is hit, and this problem only occurs in scala notebook.
I have tried jupyter-scala and Apache toree. They both have this issue. This issue is troublesome, for example, when you write nested loops as you have to tab the mouse cursor to the right position on every new line.
I have tried the conventional methods such as modifying the custom.js file, and issuing the mirrorcode commands on the browser console to set the indentUnit. It has effect on Python and R notebooks but Scala notebook just won't change.
Highly appreciate your help! I have been bothered by this issue for awhile now. Thank you very much in advance!

Matlab - import data tool

i have got a problem with the import data tool in matlab.
I just installed matlab this morning, at first it worked. However after shutting down the computer once, it doesn't work anymore.
More specifically, it opens and load data from .txt or spreadsheet, but when i click to import data to my workspace, instead of showing the progress in the waitbar it shows an error message:
IMPORT TOOL - couldn't find waitbar handles
any suggestion?
Sounds like the import tool works as intended until it cannot find the wait bar. A waitbar is a loading progress bar, which is available every basic installation of MATLAB (no toolbox required). Either the waitbar is created (do you see it?), but somehow not passed correctly through a broken connection between the import tool and the waitbar, or the waitbar function wasn't installed correctly.
I conclude your installation wasn't finished properly, so: uninstall MATLAB and reinstall it in one go (without pausing the installation).
You could also provide the system details you're installing on and the MATLAB version. Maybe someone knows of a certain condition of your particular setup that might cause the problem.

How to detect if running ipython qtconsole?

The IPython notebook and Qt console both support displaying rich representations of objects. This is done by defining, for example, a _repr_html_ method.
The problem is that these two render the HTML differently. Is there a way for me to detect whether running under ipython qtconsole so that I can use a more basic set of HTML? Preferably a documented way that is not likely to break in the future?
I have a similar problem. Doing color in IPython terminal requires calling in to windows DLL's, but the color in qtconsole seems to support the linux based escape sequences....anyway. here's what I have found. Its ugly...but it will at least tell you terminal vs. qtconsole...Oh, and I haven't tried with the notebook:
import __main__
if hasattr(__main__,"get_ipython"):
import IPython.kernel.zmq.zmqshell as z
if isinstance(get_ipython(), z.ZMQInteractiveShell):
print 'yep...its qtconsole'