每当我尝试使用Matplotlib绘制任何内容时,都会收到此警告。
必须在创建QCoreApplication之前设置属性Qt :: AA_EnableHighDpiScaling。
有人知道如何解决吗?
尝试在Matplotlib中搜索与Qt绑定有关的任何问题-仍无法解决。
这是一个会产生警告的简单代码
import numpy as np
import matplotlib.pyplot as plt
a = np.arange(1000) # the distribution doesn't matter
plt.hist(a) # here could plt.scatter or plt.plot - would still get same error.
plt.show()
答案 0 :(得分:2)
在QT中,设置应用程序标志时有一些规则,这就是其中之一,
您需要执行以下操作(将c ++用作ref,但在python中是相同的):
//first set the flags
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
//more code and then create the QApplication
QApplication mainApplication(argc, argv);
答案 1 :(得分:1)
这可以通过将matplotlib更新到最新版本来解决。首先,使用以下命令删除旧版本:
pip uninstall matplotlib
然后,使用以下命令安装最新版本:
pip install matplotlib