Label Areas in Python Matplotlib stackplot -
i generate labels inside areas of matplotlib stackplot. settle labeling line used bound area. consider example:
import numpy np matplotlib import pyplot plt fnx = lambda : np.random.randint(5, 50, 10) x = np.arange(10) y1, y2, y3 = fnx(), fnx(), fnx() arealabels=['area1','area2','area3'] fig, ax = plt.subplots() ax.stackplot(x, y1, y2, y3) plt.show()
but produce this:
the matplotlib contour plots have type of labeling functionality (though lines labeled in case of contour plot).
any (or redirection post might have missed) appreciated.
ah, heuristics. this?:
import numpy np matplotlib import pyplot plt length = 10 fnx = lambda : np.random.randint(5, 50, length) x = np.arange(length) y1, y2, y3 = fnx(), fnx(), fnx() arealabels=['area1','area2','area3'] fig, ax = plt.subplots() ax.stackplot(x, y1, y2, y3) loc = y1.argmax() ax.text(loc, y1[loc]*0.25, arealabels[0]) loc = y2.argmax() ax.text(loc, y1[loc] + y2[loc]*0.33, arealabels[1]) loc = y3.argmax() ax.text(loc, y1[loc] + y2[loc] + y3[loc]*0.75, arealabels[2]) plt.show()
which in test runs okayish:
finding best loc
fancier -- maybe 1 wants x_n, x_(n+1)
highest average value.
Comments
Post a Comment