I am using VS Code for coding python and I am having an issue regarding Matplotlib: Usually Autocomplete and Syntax Highlighting work fine but not with matplotlib. There everything is just white and I get no proposals. See this example:
I am using a virtual environment with python 3.10.8.
Do you have any ideas on how to fix this issue? Thank you!
Edit:
It is not only a VS Code problem. I also do not get any hints in pycharm.
mpl.figure
mpl.Axes
What you called is the method in the pyplot module in matplotlib. If you run your code, an error will also be reported.
Use the following code to declare your mpl
import matplotlib.pyplot as mpl
If the problem cannot be solved, please paste your import code. I will try to reproduce the problem.
Related
I am using PyCharm on my MacBook to code and now I wanted to make a simple plot. When I run the file via the usual 'Run' command (do not know what it is called), it nicely shows my plots, but when I run the file in the Python console (which I find more convenient because you can access your variables) it does not show anything. On the other hand, when I just type it in the Python console afterwards, it does work.
I have read some things about backends and other 'solutions' as I am apparently not the only one with this issue. Mine says macosx and gives the command: "Backend MacOSX is interactive backend. Turning interactive mode on." after running the file in the Python console. I tried changing the backend:
import matplotlib
# matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
but that does not work (no plot pops up). And yes, I use plt.show() after my plotting section :)
I also tried with 'QtAgg' but then I get: "ImportError: Failed to import any qt binding"
Now I am completely new to this backends stuff (I think it has to do with this), so I could really use some clear directions on how I can solve this issue.
Thanks in advance!
I am not sure we can solve this bug with some adjustment. I think you need to fresh start. I suggest you to start a new clean venv and install a new matplotlib there.
It seems like nobody had this problem before: When running the following code lines in DEBUG mode, my python crashes. I'm using python 2.7 with PyCharm 2016.3.
import matplotlib
matplotlib.use("qt4agg")
from matplotlib import pyplot as plt
If I run stepwise, it works. But if I set the breakpoint after this block, matplotlib.use() and import pyplot seem to get in each other's way. Does anyone know the problem?
So I was finally able to figure it out: The solution is to uncheck the "PyQt compatible" option under Python Debugger in the Project Settings of PyCharm. This option seems to cause the mentioned issues when using pyqt and debug mode.
As of late, I can't get my Matplotlib plots to show up. I have a very simple script:
import matplotlib.pyplot as plt
plt.plot([1,2,3])
but nothing ever shows up. If I include the line
plt.show()
then my Python process hangs.
In my ~/.config/matplotlib/matplotlibrc file I have
backend : MacOSX
interactive : True
I'm a little embarrassed to ask this question. I've been a Matplotlib user for many years and have never had this problem. I don't know where to begin to fix this problem. Help!
I'm using Matplotlib 2.0.0 with Python 3.5.2 from Anaconda.
The answer, as pointed out by #ImportanceOfBeingErnest is that the backend configuration for me wasn't working. I'm not sure if I need to install some additional libraries or not. I decided not to use the MacOSX backend and used the Qt5Agg backend. This worked just fine and I didn't have to install any new libraries.
I've just remove the line
interactive: True
enter code here
from my ~/matplotlib/matplotlibrc. It works fine with only backend: MacOSX using the plt.show() command.
I have a very strange problem that appeared recently, more or less simultaneously to my Ubuntu upgrade to 16.10.
Using Pyplot, when I use LaTeX in labels, Python3 gives back something very strange. For example, I tried to compile the example from
http://matplotlib.org/examples/text_labels_and_annotations/text_demo_fontdict.html
and I got this result:
I try to upgrade my matplotlib with pip, but nothing changed. Right now:
numpy=1.11.1, matplotlib=1.5.3
Interestingly, this problem disappears when I go back to python2, and the conversion is good.
Edit: on another machine, with Ubuntu 16.10 up-to-date, the same mpl and np versions, this bug appears in python3 AND python2.
EEdit : I did not find the problem, but a guess is a problem in the cm font of matplotlib. I tried to change the font (see e.g. How do I change the axis tick font in a matplotlib plot when rendering using Latex?), and the problem disappeared...
Thanks in advance for your help!
I'm new to Python and matplotlib. A simple script I wrote is crashing and I was able to reproduce the crash with the following code:
import matplotlib.pyplot as plt
plt.figure(1)
plt.figure(2)
#plt.show()
The error is python.exe has stopped working. If I uncomment the plt.show(), it still crashes depending on the order I close the plots (no crash if 2 is closed first, crash if 1 is closed first). I'm using Windows 7, Python 3.4, and I installed the individual modules from www.lfd.uci.edu/~gohlke/pythonlibs/. Do I have something configured incorrectly or a misunderstanding of how to use matplotlib?
You need to set the TkAgg backend explicitly. With the following code, the problem is resolved.
import matplotlib
matplotlib.use("TkAgg")
from matplotlib import pyplot as plt
Note that setting the TkAgg backend after importing pyplot does not work either; it crashes too. You need to set it before importing pyplot.
I was having this issue, I thought it was some line in my code causing the bug, but in fact the very act of importing matplotlib.pyplot was killing my program. I solved it by first running it in verbose mode:
python -v [programname].py
This shows the last action the importer does before crashing. For me, the last line of this was:
import 'PyQt5' # <_frozen_importlib_external.SourceFileLoader object at 0x000001F8EC9C0908>
This suggested to me that the dependent library PyQt5 was causing issues, so I ran pip install PyQt5, and magically everything started working.
This could be issue with python 3.x
I have tried with python 2.7 on my windows machine and it works perfectly fine!
You can either downgrade your python to 2.7 or if you feel its too late to do why dont you give it a try to call close()
Import matplotlib
matplotlib.use('wxAgg')
Import matplotlib.pyplot as plt
# your scripts
plt.close('all')
I had a similar issue in OSX when I updated to Python 3.4. IDLE was also crashing and there was a warning telling me the version was unstable.
I solved it by following the prompts and updating the version of Tcl/Tk (8.5.9) - http://www.python.org/download/mac/tcltk .
For macOS, just make sure that
~/.matplotlib/matplotlibrc contains:
backend: MacOSX
You don't need the other backends unless you specifically want them. Alternatively, perhaps you can do:
import matplotlib
matplotlib.use("MacOSX")
though I have not tested that.