每当我尝试使用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()

最佳答案

在QT中,设置应用程序标志时有一些规则,这是其中之一,

您需要执行类似操作(将c ++用作ref,但在python中是相同的):

//first set the flags
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
//more code and then create the QApplication
QApplication mainApplication(argc, argv);

10-08 09:25