2011-03-06 79 views
1

http://matplotlib.sourceforge.net/examples/api/histogram_path_demo.html你能幫我理解這個有關路徑的matplotlib代碼嗎?

我在看上面的代碼。什麼是代碼的下半部分是指:

# we need a (numrects x numsides x 2) numpy array for the path helper 
# function to build a compound path 
XY = np.array([[left,left,right,right], [bottom,top,top,bottom]]).T 

爲什麼會出現「.T」在結束了嗎?什麼是複合路徑?

# get the Path object 
barpath = path.Path.make_compound_path_from_polys(XY) 

我不明白路徑對象是什麼,有人可以解釋它或指向我的某種教程嗎?

回答

1

輔助函數將多邊形集合轉換爲「複合路徑」,即一次表示所有多邊形的對象,因此您可以調用一個繪圖操作,而不是循環播放集合。這對於獲得更好的matplotlib速度非常有用。

leftright等對象是n維陣列numpy的,其中n是多邊形的數目:left包含x的左邊緣等的座標所以陣列[[left,left,right,right], [bottom,top,top,bottom]]具有的尺寸(從出在) 2 x 4 xn(2因爲有兩個維度,4是因爲四邊形的多邊形,n是多邊形的數量),但函數期望nx 4 x 2。.T返回轉置,這對於多維數組是很方便的defined,它會反轉維度的順序。

欲瞭解更多信息,請參閱the API docsthe source code。我不知道有關matplotlib路徑對象的任何教程。