简体   繁体   English

在一个图中有多行:matplotlib.pyplot

[英]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 . 出现错误: 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. 而且似乎您正在尝试通过调用plot函数来绘制两个数组。 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: 对于在x轴上具有array1,在y轴上具有array2,您可以执行以下操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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