Based on the solutions provided by @noamgot and @jpaugh, in PyCharm 2024.2.5, I resolved the issue by unchecking the 'Show plots in tool window' option and adding matplotlib.use('TkAgg') at the beginning of my script, before importing pyplot.