To label a figure in Matplotlib, you can use the plt.annotate()
function. Here's an example:
main.py246 chars9 lines
In this example, we have plotted a simple line graph using plt.plot()
. To add a label to the maximum point, we use the plt.annotate()
function.
xy=(3, 15)
specifies the location of the point to be labeled. xytext=(2.5, 10)
specifies the location of the label text. arrowprops
specifies the attributes of the arrow connecting the label and point.
You can adjust the coordinates and attributes to customize the label as per your requirements.
gistlibby LogSnag