How to plot two numpy array

Hey guys! Can anyone tell me how to plot numpy array. I tried but its showing error.
Code:

import numpy as np
import matplotlib.pyplot as plt

a = np.random.randint(2, 10, size=(1, 10))
b = np.random.randint(5, 15, size=(1, 10))

plt.title("Line Graph")
plt.xlabel("X Axis")
plt.ylabel("Y Axis")

plt.plot(a, b, color="red")
plt.show()

Above is my code. Please tell me what’s wrong and help me correct it

import numpy as np
import matplotlib.pyplot as plt

a = np.random.randint(2, 10, size=(1, 10))
b = np.random.randint(5, 15, size=(1, 10))

plt.title("Line Graph")
plt.xlabel("X Axis")
plt.ylabel("Y Axis")

plt.plot(a[0], b[0], color="red")  # note a[0] instead of a
plt.show() 

This gets output onto the graph, I believe this is what you are looking for. Depends on if you are intending on upscaling this at all. As a simple fix, this works though.

When printing out a and b, I got something like this:

[[2 6 8 4 7 6 8 6 6 2]]

Note the “[[” and “]]”, meaning that you were not giving the plot function an iterable, by doing a[0] you would give it:

[2 6 8 4 7 6 8 6 6 2]
# instead of 
[[2 6 8 4 7 6 8 6 6 2]]

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.