J Houseman
J Houseman

Reputation: 91

Having Multiple Lines in a Plot: matplotlib.pyplot

I want to have arrays plotted in one plot.

Currently I am doing:

x1=array1
x2=array2

plt.plot(x1,'b-',label='array1',x2,'g-',label='array2')

which gives the error: positional argument follows keyword argument.

However, it works fine when the label is removed.

Does anyone have any suggestions on how to fix this error?

Upvotes: 0

Views: 54

Answers (1)

lkriener
lkriener

Reputation: 187

You have to move the keyword arguments behind the "normal" arguments of the function. Also it seems like you are trying to plot both arrays with one call of the plot function. If you want to have two lines you have to do the following:

plt.plot(x1, 'b-', label='array1')
plt.plot(x2, 'g-', label='array2')
plt.legend()

For having array1 on the x-axis and array2 on the y-axis you can do:

plt.plot(x1, x2, 'b-', label='x2 over x1')

Upvotes: 1

Related Questions