I am trying to draw a custom legend, where on one line I have some circles of increasing radius, followed by the word "Income". I consider this a beautiful way to show that a circle's size corresponds to the subject's income.
The legend has to be manually drawn. Here is how I achieve that:
class AnyObjectHandler(HandlerBase):
def create_artists(self, legend, orig_handle,
x0, y0, width, height, fontsize, trans):
legend.numpoints = 1
l1 = plt.Line2D([x0 - 40, y0 + width], [0.3 * height, 0.3 * height], color='blue',
marker='o', markersize=10, markerfacecolor="blue")
return [l1]
fig.legend([object], ['Income'], numpoints=1,
handler_map={object: AnyObjectHandler()})
The problem is that even though I tried to specify numpoints == 1
twice, the legend still comes with the default 2 markers per line. A related question (where I found how to set numpoints
to 1 is this: matplotlib Legend Markers Only Once
This is what the above code yields:
Instead of this, I would like the line to only show one circle. Doesn't matter which one.