Matplotlib is an extensively used Python library for data visualization. It is a multi-platform data visualization library built on NumPy arrays, also designed to work with the SciPy stack.
Figtext is used to add text to a figure at any location on it. You can even add the text outside the Axes. It uses the complete figure for co-ordinates, where bottom-left denotes (0, 0) and top right represents (1, 1). The centre of the figure is (0.5, 0.5).
matplotlib.pyplot.figtext(x, y, s, *args, **kwargs)
|x, y||Float||Position to place the text. It is by default in figure coordinates [0, 1]|
Example #1: A sample example demonstrating the use of figtext.
The above example places text on the bottom left of the figure of the given font size.
Example #2: We can also place text at a relative position in the figure by adjusting the values of x and y.
Alignment arguments- horizontalalignment and verticalalignment place the text in the centre while the wrap argument makes sure that the text lies within the figure width. The color argument gives the font color.
Example #3: We can also add a bounding box around the text by using the bbox argument.
Example #4: We can also use *args and **kwargs to add text properties to our plot. *args and **kwargs are used to pass multiple arguments or keyword arguments to a function.
Note: For more info refer to the article: *args and **kwargs in Python
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course