2017-02-15 89 views
2

我确实有一个图表,当我有信号时,它只包含某些值的水平线,否则没有。所以,我正在寻找一种方法来绘制这个没有垂直线。当没有信号时,线路之间可能存在间隙,我不希望线路连接,也不希望线路下降到0.有没有办法在matplotlib中绘制这样的图形?matplotlib线图不要在步骤函数中显示垂直线

enter image description here

self.figure = plt.figure() 
self.canvas = FigureCanvas(self.figure) 
axes = self.figure.add_subplot(111) 
axes.plot(df.index, df["x1"], lw=1.0, c=self.getColour('g', i), ls=ls) 
+0

显示您的代码请 – eyllanesc

+0

有几行。不知道你可能需要什么 – chrise

+0

发生什么事情是我们不禁要看到你所犯的错误或你所使用的东西。 – eyllanesc

回答

2

你正在寻找的阴谋是Matplotlib的plt.hlines(y, xmin, xmax)

例如:

import matplotlib.pyplot as plt 

y = range(1, 11) 
xmin = range(10) 
xmax = range(1, 11) 
colors=['blue', 'green', 'red', 'yellow', 'orange', 'purple', 
     'cyan', 'magenta', 'pink', 'black'] 

fig, ax = plt.subplots(1, 1) 
ax.hlines(y, xmin, xmax, colors=colors) 
plt.show() 

产生一个情节是这样的:

Matplotlib hlines plot

有关详细信息,请参阅Matplotlib documentation