Hi thank you for your help,
A matplotlib deprecation warning keeps popping up at the beginning of every run
What is seen when I run
pathto/.local/lib/python3.6/site-packages/matplotlib/backends/qt_editor/figureoptions.py:11: MatplotlibDeprecationWarning:
The support for Qt4 was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
from matplotlib.backends.qt_compat import QtGui
Here is a simple version of my code. I am running python 3.6 on Unbuntu 18.04 (I am working on upgrading this for work)
import matplotlib
matplotlib.get_backend()
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
plt.plot(df.Threshold, df.TriggerRate,'o-',color = 'g')
plt.title('Selecting Trigger Rate')
plt.xlabel('Threshold')
plt.ylabel('Trigger Rate')
plt.ylim([0,50])
plt.savefig('Tscan_now.png')
plt.show()
I have tired many things
- supressing warnings
- changing the way I plot the points
- updating matplotlib package
- trying to change which backend of matplotlib is being used
Nothing seems to remove it from the beginning of the program.
Thank you,
S
Which backend is actually being used? There are lots of things that might try and change the backend (e.g. Spyder and PyCharm both might).
If you print(matplotlib.get_backend())
at the end of your script what do you see?
If the backend isn’t TkAgg even though you’re trying to set it to that, have you tried setting it in the MPLBACKEND
environment variable? That might have a better chance of overriding everything else that likes to try and set the backend.
I have tried what you have suggested however that did not change the issue. Also, the MPLBACKEND seemed to cause an error.
This was added to the above code
import matplotlib
print(matplotlib.get_backend())
matplotlib.use('TkAgg')
print(matplotlib.get_backend())
matplotlib.use('Qt4Agg')
print(matplotlib.get_backend())
matplotlib.use('MPLBACKEND')
print(matplotlib.get_backend())
Output:
/home/.local/lib/python3.6/site-packages/matplotlib/backends/qt_editor/figureoptions.py:11: MatplotlibDeprecationWarning:
The support for Qt4 was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
from matplotlib.backends.qt_compat import QtGui
Qt5Agg
TkAgg
/usr/lib/python3.6/importlib/__init__.py:126: MatplotlibDeprecationWarning:
The matplotlib.backends.backend_qt4agg backend was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
return _bootstrap._gcd_import(name[level:], package, level)
Qt4Agg
Traceback (most recent call last):
File "horizonsnap.py", line 20, in <module>
matplotlib.use('MPLBACKEND')
File "/home/.local/lib/python3.6/site-packages/matplotlib/__init__.py", line 1154, in use
name = validate_backend(backend)
File "/home/.local/lib/python3.6/site-packages/matplotlib/rcsetup.py", line 295, in validate_backend
else _validate_standard_backends(s))
File "/home/.local/lib/python3.6/site-packages/matplotlib/rcsetup.py", line 81, in __call__
raise ValueError(msg)
ValueError: 'mplbackend' is not a valid value for backend; supported values are ['GTK3Agg', 'GTK3Cairo', 'MacOSX', 'nbAgg', 'Qt4Agg', 'Qt4Cairo', 'Qt5Agg', 'Qt5Cairo', 'TkAgg', 'TkCairo', 'WebAgg', 'WX', 'WXAgg', 'WXCairo', 'agg', 'cairo', 'pdf', 'pgf', 'ps', 'svg', 'template']
What I meant was to try setting the environment variable called MPLBACKEND
to TkAgg
(or some other backend that doesn’t error) as described in the docs: Backends — Matplotlib 3.8.2 documentation
Yes David! That seems to do the trick! Thank you so much!
This was the solution I ended up going with.
export MPLBACKEND=TkAgg
python3 script.py
Thanks,
S