0

I am reading document of the pyplot's plot function here: https://matplotlib.org/api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot. It said the Parameters x, y: array-like or scalar.

I understand how to using array-like data, but not scalar. Can anyone give some examples to show how to use scalar x, y parameter? Thanks.

1
  • For numpy, scalar is a single int or float.
    – knh190
    May 30, 2019 at 2:22

2 Answers 2

1
plot(y)

as plot(100) or some other number. It will plot a single point.

1
  • yeah, I thought about that, but one thing which confuse me was that I didn't see anything, like this:plt.plot(1, 2, "x") plt.show() Jun 5, 2019 at 2:15
0

You are thinking too much about the the definition of scalar number. For this purpose, it just means a int or float. Use the following code to plot.

plt.plot(x, y)
plt.show()

Also make sure that you have imported matplotlib correctly. The best method is

import matplotlib as plt

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.