Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix: "Attribute Qt::AA_EnableHighDpiScaling must be set before QCoreApplication is created." warning

Anytime I try to plot anything with Matplotlib I get this warning.

Attribute Qt::AA_EnableHighDpiScaling must be set before QCoreApplication is created.

Does anyone know how to fix it?

Tried googling any issues related to Qt bindings in Matplotlib - still couldn't fix this.

Here is a simple code that would yield the warning

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()
like image 392
Rytis Jonynas Avatar asked Aug 12 '19 07:08

Rytis Jonynas


2 Answers

This can be solved by updating matplotlib to the latest version. First, remove the older version using:

pip uninstall matplotlib

Then, install the latest version using:

pip install matplotlib
like image 140
MI Alam Avatar answered Sep 16 '22 14:09

MI Alam


in QT you have some rules when setting application flags, and that is one of them,

you need to do something like (c++ as ref but in python is the same):

//first set the flags
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
//more code and then create the QApplication 
QApplication mainApplication(argc, argv);
like image 26
ΦXocę 웃 Пepeúpa ツ Avatar answered Sep 20 '22 14:09

ΦXocę 웃 Пepeúpa ツ