Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw a curly bracket over two lines in a matplotlib legend

I would like to draw a curly bracket for two lines of the legend, like so:

curly bracket indicates a shared property for two legend entries

I am able to create everything with pyplot except for the curly bracket using

plt.plot([],[],"ro",label="a")
plt.plot([],[],"bo",label="b")
plt.legend(frameon=False,loc="upper left")
plt.annotate("some property",
            xy=(0.31, 0.7), xycoords='figure fraction',
            xytext=(0.31,  0.79), textcoords='figure fraction',
            arrowprops=dict(arrowstyle="-",lw=0
                       )
            )
 plt.plot() 

Any help would be greatly appreciated.

like image 313
Johann Avatar asked Jan 28 '23 16:01

Johann


1 Answers

Thanks to the comment by ImportanceOfBeingErnest I realized the obvious solution of simply adding another annotation:

plt.annotate(r"$\}$",fontsize=24,
            xy=(0.27, 0.77), xycoords='figure fraction'
            )
like image 113
Johann Avatar answered Feb 02 '23 10:02

Johann