Anaconda on Mac: Can't set Matplotlib backend to Agg - python-3.x

I want to set Spyder to use a non-interactive matplotlib backend, so that plot figures do not pop up but I can still save figures to file, like this hint.
However, it looks like Spyder automatically imports matplotlib and sets the backend internally somewhere, so any call I make to matplotlib.use() pops an error saying that MPL has already been called.
Prefs show that "automatically import PyLab" is disabled. Also there is no 'Agg' backend in the dropdown list.
How do I use a non-interactive backend?
Or preferably: how can I allow command-line setting of the backend again? (I would like my script to choose whether to use the interactive/non-interactive backends depending on some variables, before MPL import.)
Spyder prefs Screenshot:
Versions/attempt, on Mac OS 10.13.6 (shows MPL already imported!):
Python 3.6.6 |Anaconda custom (64-bit)| (default, Jun 28 2018, 11:07:29)
IPython 6.5.0 -- An enhanced Interactive Python.
>> matplotlib
Using matplotlib backend: Qt5Agg

(Spyder maintainer here) As mentioned by #ImportanceOfBeingErnest in his comment above, you simply need to turn off the option called Activate Support in the screenshot you posted to be able to set by yourself the Matplotlib backend you want to use in your code.

Related

IPython shell via embed() not showing colors

I use the following snippet to drop to an interactive IPython CLI from my code:
from IPython import embed
# do some things
embed()
But no syntax highlighting or any other color shows up.
If, in contrast, I start ipython simply with
ipython3
Then colors show up as expected.
How can I get colors/syntax highlighting when embedding IPython like this?
IPython==7.21.0
python3==3.7.5
Also on gh issues
Has posted on Github by me
This is a known problem as you can see here
I suggest you to run your code as follow:
from IPython import embed
# do some things
embed(colors="neutral")
The supported colors are (as you can read here): Neutral, NoColor, LightBG, Linux

Jupyter's tab auto-complete is not working for several libraries like- sklearn, numpy, seaborn, pandas and matplotlib etc

Whenever I am using jupyter in the default directory (used by jupyter after installing anaconda) tab auto complete works fine. After entering a dot if I press the tab the list of methods and attributes appears.
Now, if I launch Jupyter notebook from a different location (say D drive) using anaconda prompt (command line), jupyter notebook appears, but for several libraries like sklearn, numpy, seaborn, pandas and matplotlib tab auto-complete after a dot is not working. However, when I write:
from sklearn.
and then press tab then I can see the options, similarly for other libraries too (below is one such screenshot).
Surprisingly the same never happens when I write:
import numpy as np
import sklearn
import seaborn as sb
np. # nothing appears upon pressing Tab after a dot
sb. # nothing appears upon pressing Tab after a dot
sklearn. # nothing appears upon pressing Tab after a dot
I have read some solutions on the internet where they mention about some plugin/extensions to use, but I don't want them to be used, I kind of prefer what jupyter already offers.
Could someone please help me with this issue...?
P.s.: I'm not still sure with what all other libraries the issue still persists, I happen to frequently use these so far....

How can Pycharm (with matplotlib) show me my graphs in the same Py charm, next to my code?. Not in additional windows

i am using Matplotlib with Pycharm in a Mac osx. When I am making a graph, and I code plt.show() pycharm opens another window. And if there is 2 graphs, to see the 2nd one I have to close the first one. And I want to see both together.
There is a option to show the two graph in the same window, where my code is?
Thanks very much.
This link may help:
IPython magic commands
Using Jupyter notebooks you can achieve what you want by using %matplotlib inline. It seems from the link above that PyCharm may have some way to enable this same functionality.
See also: Inline plots in the scientific view

Warning in Spyder iPython window whenever I create a canvas in Vispy

Every time I create a vispy Canvas instance in Spyder:
from vispy import app
class Canvas(app.Canvas):
def __init__(self):
app.Canvas.__init__(self)
canvas = Canvas()
I start to get warnings like the following in the iPython window:
WARNING: QSocketNotifier: Multiple socket notifiers for same socket 1048 and type Read
Once the canvas instance is created, whenever I type in the iPython console in Spyder, this error starts to occur, so I can't do things like explore modules via tab completion (the warning obliterates the dropdown menu). It also tends to randomly insert itself in stack traces and other places in the console, generally disrupting my workflow (in non-catastrophic ways).
I tried turning off the Warning by turning off Real-time code analysis, as suggested here:
How to suppress a certain warning in Spyder editor?
But it didn't affect the behavior.
I am in Spyder version: 3.2.8 (in an environment that includes spyder-kernels 0.2.6), Python version: 3.6.6, Qt version: 5.6.2, PyQt5 version: 5.6 in Windows 10. This has happened on all three Windows 10 machines I use. I'm running this all in Anaconda. When I run the above code just in the python shell, or from the pure iPython shell, I do not get the warning.

Widgets not showing in NBViewer

I have an iPython Notebook with an interactive slider widget:
To share the notebook, I would like to use the link provided by NBViewer. This would allow me to share the notebook with people that don't use Python. Unfortunately, the widget does not show when viewing the NBViewer link:
Is there something I need to do to make widgets work with NBViewer?
Widgets are not shown in nbviewer with current ipython 2.x.
IPython 3 is supposed to add persistent widgets that can be shown by nbviewer.
The release of ipython 3 was scheduled for this fall but it is likely to happen early next year.
I had to downgrade ipywidget from version 7.0.3 to get nbviewer showing ipywidget.
pip install ipywidgets==6.0.0

Resources