Reputation: 161
http://matplotlib.sourceforge.net/examples/api/histogram_path_demo.html
I'm looking at the above code. What does the bottom half of the code mean:
# 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
Why is there a ".T" on the end? What is a compound path?
# get the Path object
barpath = path.Path.make_compound_path_from_polys(XY)
I don't understand what a path object is, can someone explain it or point me to some sort of tutorial?
Upvotes: 1
Views: 380
Reputation: 44128
The helper function converts a collection of polygons into a "compound path", an object that represents all the polygons at once, so you can call one drawing operation instead of looping over your collection. It's mainly useful to get better speed out of matplotlib.
The left
, right
, etc objects are n-dimensional numpy arrays, where n is the number of polygons: left
contains the x coordinate of the left edge, etc. So the array [[left,left,right,right], [bottom,top,top,bottom]]
has dimensions (from out to in) 2 x 4 x n (2 because of two dimensions, 4 because of four-sided polygons, n is the number of polygons) but the function expects n x 4 x 2. The .T
returns the transpose, which is handily defined for multidimensional arrays so that it inverts the order of dimensions.
For more information, see the API docs or the source code. I don't know of any tutorials about matplotlib's path objects.
Upvotes: 1