Sunday 9 July 2017

Python matplotlib: insets and aligned legends

Sometimes it is needed to create a plot with several lines and to assign a legend to each of them, which quite often ends in cumbersome and clunky legends. In my opinion, a more elegant way is include the legend as aligned text aside to each plot line, which is possible using Python and matplotlib.

Furthermore, to better highlight some details it is also possible to use an inset, hence to add a box which zooms a particular detail of the plot.

In the following is the Python code. The style is optimised for an IEEEtran journal.