2014-09-26 19 views
0

我有以下代碼:如何繪製matplotlib中每個點的直線?

fig = pylab.figure() 
ax = fig.gca() 

ax.plot_date(dates, df['y']) 

ax.xaxis.set_major_locator(
    matplotlib.dates.WeekdayLocator(byweekday=matplotlib.dates.SA, interval=2) 
) 
ax.xaxis.set_major_formatter(matplotlib.dates.DateFormatter('%a %d\n%b %Y')) 

這給enter image description here

,但我想每個點是一條直線。我不會爲這條線的y值而煩惱,但它應該從小到大排列。

如何繼續?

+2

查看matplotlib模塊中的vlines(對於垂直線)。 – 2014-09-26 16:48:13

+0

@DanielThaagaardAndreasen,請將你的評論擴展爲答案。乾杯。 – 2014-09-26 17:07:07

回答

0

這可以使用像這樣的matplotlib庫中的垂直線來完成。

from matplotlib import pylab 

fig = pylab.figure() 
ax = fig.gca() 
dates = range(10) 
ax.vlines(dates, ymin=-1, ymax=1.5, color='r') 
pylab.show() 

我在函數中添加了一些或多或少的隨機參數。在matplotlib中可以添加更多其他繪圖功能。