I am producing some plots in matplotlib and would like to add explanatory text for some of the data. I want to have a string inside my legend as a separate legend item above the '0-10' item. Does anyone know if there is a possible way to do this?
This is the code for my legend:
ax.legend(['0-10','10-100','100-500','500+'],loc='best')
Alternative solution, kind of dirty but pretty quick.
Sure.
ax.legend()
has a two argument form that accepts a list of objects (handles) and a list of strings (labels). Use a dummy object (aka a "proxy artist") for your extra string. I picked amatplotlib.patches.Rectangle
with no fill and 0 linewdith below, but you could use any supported artist.For example, let's say you have 4 bar objects (since you didn't post the code used to generate the graph, I can't reproduce it exactly).