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
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745255740a4618944.html
评论列表(0条)