admin管理员组文章数量:1416651
I have created a sin wave in matplotlib and when I run the code the the window opens and closes immediately without showing anything. What can I do to display the results.
import torch, time
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# Create sine wave data
pi_tensor = torch.linspace(0, 2 * np.pi, 100)
sin_result = torch.sin(pi_tensor)
# Plot the sine wave
plt.plot(pi_tensor.numpy(), sin_result.numpy())
plt.show()
I have created a sin wave in matplotlib and when I run the code the the window opens and closes immediately without showing anything. What can I do to display the results.
import torch, time
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# Create sine wave data
pi_tensor = torch.linspace(0, 2 * np.pi, 100)
sin_result = torch.sin(pi_tensor)
# Plot the sine wave
plt.plot(pi_tensor.numpy(), sin_result.numpy())
plt.show()
Share
Improve this question
asked Feb 2 at 21:29
Sharks CharlatansSharks Charlatans
211 silver badge2 bronze badges
0
1 Answer
Reset to default 1By default, if you're running this code in an interactive window, plt.show()
should block until the window is closed. If you're running it in a non-interactive window, it won't block by default, and that is most likely your problem.
Use
plt.show(block=True)
to force it to block.
Ref: https://matplotlib./stable/api/_as_gen/matplotlib.pyplot.show.html
本文标签: pythonmatplotlib closes window immediatelyStack Overflow
版权声明:本文标题:python - matplotlib closes window immediately - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745255740a2650089.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论