Search code examples
pythonmatplotlibvisual-studio-code

Matplotlib Plot Not Responding in VSCode Debug Mode


I'm encountering an issue when trying to plot a simple graph using Matplotlib in Python while in debug mode in VSCode. The plot works perfectly in normal execution mode, but when I set a breakpoint and run the code in debug mode, the plot window becomes unresponsive.

Example Code:

import matplotlib.pyplot as plt

# Sample data
x = [1, 2, 3, 4, 5]
y = [10, 20, 25, 30, 40]

# Plotting the data
plt.plot(x, y)
plt.title('Sample Plot')
plt.xlabel('x-axis')
plt.ylabel('y-axis')

# Show plot
plt.show()

In normal execution mode, the plot window appears and is responsive. In debug mode with a breakpoint, the plot window appears but becomes unresponsive and eventually throws a "not responding" error.

debug mode error not response

I tried using different Matplotlib backends, but none of them resolved the issue. I expect to be able to plot graphs using Matplotlib in debug mode vscode without the plot window becoming unresponsive.


Solution

  • I also had this issue. I got it working again by running Python 3.11.9 instead of 3.12.*, and I also had to switch to matplotlib 3.8.3 instead of 3.9.*. Has been driving me crazy for a couple weeks. So, try setting up a virtual environment in VSCode with matplotlib 3.8.3 and switching your interpreter to 3.11.9 in that environment.