2017-05-14 72 views
0

例如,我有几行类似的坐标:如何在图中移动几行以避免重叠?

import matplotlib.pyplot as plt 

x1 = [-1, 0, 1, 1, 1, 0, -1, -1, 0, 0, 1] 
x2 = x1[:] 

plt.pyplot(x1, color='red') 
plt.pyplot(x2, color='green') 
plt.show() 

当然它会显示仅与一个橙色线组合的颜色图表。有没有什么办法(matplotlib函数或一些方法)使第二行的一个小的转变,以获得很好的图形(线彼此接近)?

P.S.在我真正的问题中,我需要绘制带有y值(0,-1,1)的10行图形,所以这些行经常重叠。我想在它们之间增加一些空间。

在此先感谢。

回答

2

您可以为其中一行添加少量数据,例如:通过使用numpy数组并添加一些数字,x2 = x1 + 0.1

import matplotlib.pyplot as plt 
import numpy as np 

x1 = np.array([-1, 0, 1, 1, 1, 0, -1, -1, 0, 0, 1]) 
x2 = x1 + 0.1 

plt.plot(x1, color='red') 
plt.plot(x2, color='green') 
plt.show() 

enter image description here

该溶液当然是不理想的。为了使线适合很好地对对方,你可能因此选择使用类似于这个问题讨论的一个解决方案: In matplotlib, how can I plot a multi-colored line, like a rainbow

结果将然后寻找更愉快喜欢

enter image description here

相关问题