你能帮我理解这个关于路径的matplotlib代码吗?

时间:2011-03-06 05:42:40

标签: path matplotlib

http://matplotlib.sourceforge.net/examples/api/histogram_path_demo.html

我正在查看上面的代码。代码的下半部分是什么意思:

# 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 个答案:

答案 0 :(得分:1)

辅助函数将多边形集合转换为“复合路径”,这是一个同时表示所有多边形的对象,因此您可以调用一个绘图操作而不是循环遍历集合。从matplotlib中获得更好的速度主要是有用的。

leftright等对象是n维numpy数组,其中n是多边形的数量:left包含左边缘的x坐标,等等。数组[[left,left,right,right], [bottom,top,top,bottom]]具有尺寸(从out到in)2 x 4 xn(2因为两个维度,4因为四边形多边形,n是多边形的数量)但函数需要nx 4 x 2。 .T返回转置,对于多维数组,它很方便defined,以便它反转维度的顺序。

有关详细信息,请参阅the API docsthe source code。我不知道有关matplotlib的路径对象的任何教程。