0

I am using python v3.6 with pycharm and anaconda. I tried to run the code below to plot a simple sine wave;

import numpy as np
import matplotlib.pyplot as plt

# Generate a sequence of numbers from -10 to 10 with 100 steps in between
x = np.linspace(-10, 10, 100)
# Create a second array using sine
y = np.sin(x)
# The plot function makes a line chart of one array against another
plt.plot(x, y, marker="x")
pass

The code runs smoothly without error but no plot appears. How do I get the plot to appear?

1 Answer 1

4

You're missing plt.show() at the end.

import numpy as np
import matplotlib.pyplot as plt

# Generate a sequence of numbers from -10 to 10 with 100 steps in between
x = np.linspace(-10, 10, 100)
# Create a second array using sine
y = np.sin(x)
# The plot function makes a line chart of one array against another
plt.plot(x, y, marker="x")
plt.show()
pass

or, if you want to save it into a file

plt.savefig("my_file.png")
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I will mark it as the answer. cannot upvote due to lack of points.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.