Title and legend are pieces of text that facilitate quick comprehension of the data context. Although a title is not required or recommended, sometimes, such as in inline figures of many scientific publications, adding a title for your plot often helps make the message clear, especially when your figure is not accompanied by explanatory text. For plots with multiple datasets, it is a good practice to keep a data legend with a distinct color or pattern code labeled with the corresponding identities.
The title of a figure can be set by pyplot.title()
or axes.set_title()
. Text properties can be supplied as keyword arguments.
Adding a legend of data labels in Matplotlib is as simple as setting label='yourlabel'
when plotting and adding pyplot.legend()
before pyplot.show()
. By default, Matplotlib finds the "best" location to prevent the legend from overlapping with data. You may also specify a location using pyplot.legend(loc='3', **kwargs...