I'm using mpld3 to visualize interactive plots in ipython notebook
It used to work fine. I installed a new computer, with the latest versions of Ipython and Matplotlib.
But when I run:
enable_notebook()
plot([1,2],[1,2])
instead of getting a plot I get only:
Out[8]: [<matplotlib.lines.Line2D at 0x5cb0850>]
what am I doing wrong?
This is probably related to upgrading the library, and having old versions of the javascript hanging around. We haven't put it up on the mpld3 website yet, but you can see some relevant information in the FAQ section of the mpld3 git repository.
Related
I tried this code in Spyder (python 3.9)
import networkx as nx
cg= nx.complete_graph(10, create_using=nx.DiGraph())
nx.draw(cg)
but I got an empty graph in the plot console.
I was not able to reproduce the problem:
Moving some of the information from the comments below:
Since it had previously shown the graph and now it doesn't and even Matplotlib graphs show up blank and you are running 5.1.5 (which had a lot of other issues), here are some steps to update Spyder itself:
Go to Anaconda Navigator and add conda-forge to your list of sources (Spyder is not being updated on the default channel now):
Go to the Spyder item in that window and click Upgrade (it's grayed out on my setup because I already have the latest version):
When searching about this issue, I came across some questions asking the opposite, i.e., package opens in iPython but not in Jupyter Notebook. But in my case, its the opposite. That's why I posted this question.
I added path\to\anaconda3 and path\to\anaconda3\Lib\site-packages in the environment variable, but it doesn't solve the issue.
I can see the packages in the site-packages folder:
But I just can't import some of the packages in iPython:
or with python in the anaconda cmd:
But it works fine in Jupyter Notebook:
What do/can I do to fix this?
Here's some more info if it helps:
(base) C:\Users\h473>where python
C:\Users\h473\AppData\Local\Continuum\anaconda3\python.exe
(base) C:\Users\h473>where conda
C:\Users\h473\AppData\Local\Continuum\anaconda3\Library\bin\conda.bat
C:\Users\h473\AppData\Local\Continuum\anaconda3\Scripts\conda.exe
(base) C:\Users\h473>where pip
C:\Users\h473\AppData\Local\Continuum\anaconda3\Scripts\pip.exe
P.S.: It doesn't happen for all packages, only some packages, as shown for pandas, numpy and matplotlib in the screenshot below.
When you are using matplotlib (and seaborn is built on top of it) it needs to use a so called backend that is used to display the actual GUI with the plot in it once you execute for example matplotlib.pyplot.show().
When you are running a Jupyter Notebook with matplotlib in inline mode (default I think, but not sure), then a Jupyter specific backend is used (module://ipykernel.pylab.backend_inline). That makes sense, since the plots should not appear in separate windows, but be displayed inside the notebook itself.
When you are in an interactive python or iPython session however, Qt5 was used as
import matplotlib
print(matplotlib.rcParams["backend"]) # this prints the backend that would be loaded when trying anything with pyplot
has revealed. Since you get the error youa re getting, it looks like your QT5 installation is broken. You can try to reinstall them using the conda commands, but for now you could also fall back to using a different backend, that you need to specify before trying to load seaborn:
import matplotlib
matplotlib.use("TkAgg") #use backend TkAgg
import seaborn
You can also change the default backend being loaded to TkAgg by creating a matplotlibrc file in C:\Users\<your name>\.matplotlib\ with
backend : TkAgg
in it.
I can run my program in the terminal, but when I run it directly using Pycharm, it gives
AttributeError: module 'matplotlib' has no attribute 'verbose'
I think I found the answer. I was having the same problem. In PyCharm Professional 2017.3, go to File | Settings | Tools | Python Scientific. There is an option there to "Show plots in toolwindow". Uncheck this option. Then it should work ok. It has something to do with PyCharm trying to help you by allowing you to interact with your plots - as hinted at in this issue discussion. https://youtrack.jetbrains.com/issue/PY-26652
Try to install older version of matplotlib like 2.1.0 rather than v 2.2.0
use:
pip uninstall matplotlib
pip install matplotlib==2.1.0
This is an error on the matplotlib side, verbose was unintentionally removed in matplotlib 2.2.0.
See this issue.
This is fixed from the matplotlib side as of version 2.2.2. (Release here)
If updating is not an option, one less ideal option could be to locate the __init__.py inside the matplotlib folder, and add the line
verbose = Verbose()
after the Verbose() class - that should be around line 384 in the current version.
if anyone is having issue such as: module matplotlib has no attribute 'artist'.
Try this method below by removing matplotlib
pip uninstall matplotlib
then reinstall it again worked for me
pip install matplotlib==3.0.0
In the most recent version of PyCharm (Profession 2020.2), this issue if fixed. You can use matplotlib 2.2.0+ and make use of the "Show plots in tool window" feature at the same time.
I've just started using Light Table and can't get iPython working under OSX 10.10. Relevant version numbers are iPython 3.2.1, Python 3.4.3 or 2.7.10, and LightTable version 0.7.2 (installed via a Homebrew Cask and .zip file).
Evaluating Python code works as I'd expect and I get nice tab-completion, but I can't get any graphical output. The "Connection Bar" shows a python connection rather than ipython even though ipython is available on the command line and I can successfully run ipython notebook and have it pop up a web-browser (this requires a working copy of pyzmq).
Neither Python 2.7 nor 3.4 work, and I've tried the official LT .zip as well as installing as brew cask install lighttable.
Changing my User.behaviours to explicitly reference the "correct" virtualenv:
[:app :lt.plugins.python/python-exe "/Users/smason/.virtualenvs/py3/bin/python"]
[:app :lt.plugins.python/ipython-exe "/Users/smason/.virtualenvs/py3/bin/ipython"]
doesn't seem to affect things (verified by getting appropriate errors when misspelling binary, and by running print(sys.version) and looking at output in console).
The problem was that iPython support with Light Table is pretty out of date. It is using features that were exposed in pre-1.0 versions of iPython and it's not been updated while iPython's API has changed.
The most minimal change to Light Table that fixed this for me is in:
https://github.com/LightTable/Python/pull/31
If you're patching your own install you would want to modify:
LightTable.app/Contents/Resources/app.nw/plugins/python/py-src/ltipy.py
but with iPython 4 being released yesterday more code needs to change—hopefully (if you're reading this) I'll get around to making this larger change.
I've just completed the installation of Anaconda on my MacBook Pro (running OS X 10.10 Yosemite). I installed the recommended package, which includes Python 2.7.
The versions I have of the (I think) pertinent packages are:
Numpy: 1.9.0
Scipy: 0.14.0
IPython: 2.2.0
matplotlib: 1.4.0
I was following the instructions for testing the installation listed here:
https://python4astronomers.github.io/installation/python_install.html#test-the-installation
Everything was fine, except for running IPython with matplotlib integration. Based on the guide on that page (which do not tell you to explicitly import matplotlib), and on my limited knowledge of IPython, I was under the impression that invoking IPython with
ipython --matplotlib
would "automagically" import the matplotlib modules somehow.
However, when I typed the line below into the IPython interpreter session:
print(matplotlib.__version__)
an error message was displayed which indicated that matplotlib was unavailable:
NameError
Traceback (most recent call last)
<ipython-input-1-dc737d9da186> in <module>()
----> 1 print(matplotlib.__version__)
NameError: name 'matplotlib' is not defined
However, IPython does say this when it is invoked:
IPython 2.2.0 -- An enhanced Interactive Python.
...
Using matplotlib backend: MacOSX
I know that IPython develops at a rapid pace, so my question is:
Did I miss something in the installation process (although it was performed using the Anaconda pre-compiled binary installer), or has the was matplotlib integration is achieved with IPython changed, or could the set of instructions I followed for testing the installation be missing something? I checked that site for a way to contact those guys before coming here, but I could not find it.
I've been through period of extraordinary hair loss due to having pulled huge tufts of it out while trying to sort out $PATH issues with Python and related problems while using Python on OS X, so this time I went with Anaconda and am just trying to quash any problems that may arise before I further complicate the situation by installing other modules not included with Anaconda.
Thanks in advance!
All the --matplotlib option does is set IPython up to display images generated by matplotlib so they are not blocking. It doesn't import anything. You still have to import matplotlib manually.