How to accommodate fig.show() using matplotlib.pyplot python with pycharm?

Viewed 110

Here is a basic code

import numpy as np
import matplotlib.pyplot as plt

# prepare data
x = np.linspace(0, 2*np.pi, 100)
y1 = np.cos(x)

# render the figure
fig, ax = plt.subplots()
ax.plot(x, y1, label="y1", ls="-", color="black")
ax.legend()
ax.set_xlabel("x, x units")
fig.show()

The figure appeared for like a second and then it disappears:

enter image description here

Initial question: The plot appeared briefly (1 sec) and then disappears because my pycharm isn't consistently running.

Update: So @9769953 figured that I can use plt.show() instead which is working. But the new question is if I insist using fig.show(), how can I change my pycharm settings to accommodate this?

The reason why fig.show() doesnt work.

enter image description here

FYI: https://matplotlib.org/stable/api/figure_api.html#matplotlib.figure.Figure.show

0 Answers
Related