I'm working on contourf to get the contours of some gridded data. But I do not understand how to get the correspondent level of every path (neither do I know for polygons) returned by contourf.
Needless to say this information is present, since when plotted different levels correspond to different colours.
Trivial code example:
import numpy
from matplotlib import pyplot
grid = numpy.empty((5,5))
grid[:2] = 0
grid[2:] = 2
print(grid)
contour_set = pyplot.contourf(range(5), range(5), grid, levels=[1,2])
#at least two levels are needed so i give a random one
polygon = contour_set.collections[0].get_paths()[0].to_polygons()[0]
print(polygon)
Here the path is clearly of level '2' but the issue comes when there are many different levels.