Matplotlib弃用警告
我正在使用Matplotlib库在PyQt5 windows中实现图形。运行代码时,会出现以下警告错误:Matplotlib弃用警告,matplotlib,pyqt5,warnings,Matplotlib,Pyqt5,Warnings,我正在使用Matplotlib库在PyQt5 windows中实现图形。运行代码时,会出现以下警告错误: Warning (from warnings module): File "C:\Users\yagom\OneDrive\Escritorio\SUSKIND\Código fuente\wsS1.py", line 6 from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as F
Warning (from warnings module):
File "C:\Users\yagom\OneDrive\Escritorio\SUSKIND\Código fuente\wsS1.py", line 6
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
MatplotlibDeprecationWarning:
The matplotlib.backends.backend_qt4agg backend was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
Warning (from warnings module):
File "C:\Users\yagom\OneDrive\Escritorio\SUSKIND\Código fuente\wsS1.py", line 106
ax.set_yticklabels(ax.get_yticks(), {'family':'Cambria','size':'9','color':'black'}) #
MatplotlibDeprecationWarning: Passing the fontdict parameter of _set_ticklabels() positionally is deprecated since Matplotlib 3.3; the parameter will become keyword-only two minor releases later.
Warning (from warnings module):
File "C:\Users\yagom\OneDrive\Escritorio\SUSKIND\Código fuente\wsS1.py", line 75
ax.set_xticklabels(ax.get_xticks(), {'family':'Cambria','size':'9','color':'white'})
UserWarning: FixedFormatter should only be used together with FixedLocator
这里有一个小的可重复的例子,警告也会出现
import sys, time, random
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib import ticker
class wS1(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('Interfaz')
self.setFixedSize(1440,880)
self.initUI()
def initUI(self):
def set_GraphWidget_1 (ys=[0,1,0,2,26,22,14,12,4,2],remark=3):
self.figure = Figure(figsize=(3,1.8))
self.Graph_1 = FigureCanvas(self.figure)
ax = self.figure.add_subplot(111)
self.figure.tight_layout()
ax.clear()
ax.grid(True,axis='both',linestyle=':')
ax.set_yticklabels(ax.get_yticks(), {'family':'Cambria','size':'9','color':'black'})
ax.set_xticklabels(ax.get_xticks(), {'family':'Cambria','size':'9','color':'white'})
ax.tick_params(which='major', width=0.75, length=5, color='grey')
ax.tick_params(which='minor', width=0.5, length=2.5, color='grey')
for spine in ax.spines.values():
spine.set_edgecolor('grey')
ax.set_facecolor('#f4f2f1')
ax.yaxis.set_major_locator(ticker.MultipleLocator(10))
ax.yaxis.set_minor_locator(ticker.MultipleLocator(5))
ax.xaxis.set_major_locator(ticker.MultipleLocator(1))
ax.yaxis.set_major_formatter('{x} %')
ax.plot(ys,linewidth=1,markersize=3,marker='o',color='#e66f00',zorder=0)
if remark != None:
ax.scatter(remark,ys[remark],s=35,linewidth=0.5,edgecolors='black',color='#e66f00',zorder=1)
def set_GraphWidget_2 (ys=[120,66,19,19,14,9,9,5,0,6]):
self.figure = Figure(figsize=(3,2.5))
self.Graph_2 = FigureCanvas(self.figure)
ax = self.figure.add_subplot(111)
self.figure.tight_layout()
ax.clear()
ax.grid(True,axis='both',linestyle=':')
ax.set_yticklabels(ax.get_yticks(), {'family':'Cambria','size':'9','color':'black'}) #
ax.tick_params(which='major', width=0.75, length=5, color='grey')
ax.tick_params(which='minor', width=0.5, length=2.5, color='grey')
for spine in ax.spines.values():
spine.set_edgecolor('grey')
ax.set_facecolor('#f4f2f1')
ax.yaxis.set_major_locator(ticker.MultipleLocator(20))
ax.yaxis.set_minor_locator(ticker.MultipleLocator(5))
ax.xaxis.set_major_locator(ticker.MultipleLocator(1))
ax.yaxis.set_major_formatter('{x}')
ax.xaxis.tick_top()
width = 0.08
opacity = 0.85
xs = range(1,len(ys)+1)
ax.bar(xs,ys,width,color='#e66f00')
set_GraphWidget_1()
set_GraphWidget_2()
self.Lay = QVBoxLayout()
self.Lay.addWidget(self.Graph_1)
self.Lay.addWidget(self.Graph_2)
self.setLayout(self.Lay)
app = QApplication(sys.argv)
window = wS1()
window.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
我尝试过几次改变,但似乎都不起作用。有人能解释一下我应该对代码做什么更改吗?我将非常感激。关于滴答声警告。您应该将“设置记号”函数拆分为2,一个用于值,一个用于标签。例如:
ax.set_yticks([0,50,80])
ax.set_yticklabels(['start', 'mid', 'end])
请通过调用matplotlib.backends.backend\u qt4agg import…为您使用PyQt4后端提供一个示例。尝试将其从matplotlib.backends.backend\u qt5agg import更改为
。
。谢谢!但滴答声警告依然存在。你有办法解决这个问题吗?