2017-02-15 87 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