PyCharm and matplotlib: not responding

Answered

This is a recurring problem that I have had with PyCharm. When trying to display plots with `plt.show()` a black window opens and is not responding. I can only close it. Usually, using `matplotlib.use("qt5agg")` would fix the problem but it seems to no longer be the case. I really don't know what to do.

 I run the Professional edition on Ubuntu 20.04, all my python packages are up to date.

0
3 comments

Which PyCharm version are you running? Also, share a quick example if possible. I just tried with the following example on 2024.3.5 with matplotlib  3.10.1

import matplotlib.pyplot as plt
import numpy as np
def test():    
  plt.figure()    
  plt.imshow(np.random.randint(0, 10, (100, 100)))
  plt.show()

test()

And it worked normally;

0

PyCharm 2024.3.5 (Professional Edition)
Build #PY-243.26053.29, built on March 17, 2025

Runtime version: 21.0.6+8-b631.39 amd64 (JCEF 122.1.9)
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.awt.X11.XToolkit
Linux 5.15.0-134-generic
Ubuntu 20.04.6 LTS; glibc: 2.31

I use matplotlib 3.10.0.

I provide you with 2 code examples:

### CODE 1
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import use

# use("Qt5Agg")

freq = 440
amplitudes = np.array([1, 0.263, 0.14, 0.099, 0.209, 0.02, 0.029, 0.077, 0.017, 0.01])

X = np.linspace(0, 5/freq, 1000)

freqs = freq * np.arange(1, len(amplitudes) + 1)
y = (np.sin(2 * np.pi * (freqs[:, None]) * X[None, :]) * amplitudes[:, None]).sum(axis=0)

plt.figure(figsize=(10, 5))
plt.plot(X, y, color='r')
plt.show()

 

### CODE 2
import numpy as np
import pyxu.operator as pxop
from scipy.signal import fftconvolve
from matplotlib import use
import matplotlib.pyplot as plt
use("qt5agg")

L = 50*2
N = 10_000

ratio = N//L

# kernel is a triangle with half width of hw
hw = 0.1/2
height = 1 / hw

lambda_ = .001 * L

if __name__=="__main__":
    # measured signal: narrow gaussian + wide one centered on 0.5
    center_wide = 0.5
    sigma_wide = 0.15/2
    cener_narrow = 0.35
    sigma_narrow = 0.03/2

    X = np.linspace(0, 1, N)
    y_wide = np.exp(-((X - center_wide) ** 2) / (2 * sigma_wide ** 2)) / (sigma_wide * np.sqrt(2 * np.pi))
    y_narrow = 0.5 * np.exp(-((X - cener_narrow) ** 2) / (2 * sigma_narrow ** 2)) / (sigma_narrow * np.sqrt(2 * np.pi))
    y = y_wide + y_narrow

    plt.figure(figsize=(10, 5))
    plt.plot(X, y, color='r')
    plt.title("source signal")
    plt.ylim(-0.1, 1.05*y.max())
    plt.show()

What happens ?

  • CODE 1:
    • The plot is not responding, as in the first screenshot below.
    • If I uncomment # use("Qt5Agg"), I get what I want, second screenshot.

       

  • CODE 2:
    • Black window in both cases, independently of using “Qt5Agg” or not.

 

I hope it is clearer, let me know if I can provide more information! Thank you for your help.

 

 

 

 

0

I was unable to replicate the same behavior on both cases: 

 

Please try the 2025.1 EAP available via the Toolbox App; Make sure to create a brand new project with a new interpreter just in case; 

In case it persists, please create a new bug report on YouTrack and make sure to provide the IDE UI logs from Help | Collect Logs and Diagnostic Data

0

Please sign in to leave a comment.