简体   繁体   中英

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?

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM