To display text with matplotlib, you can use the plt.text()
function. This function allows you to add text to a specific location on the plot by specifying the x and y coordinates and the text itself. You can also customize the font size, font color, font style, and alignment of the text. Additionally, you can use LaTeX expressions to format mathematical symbols and equations in the text. Overall, plt.text()
provides a flexible way to add informative text to your matplotlib plots.
What is the default text box border color in matplotlib?
The default text box border color in matplotlib is black.
What is the default text alignment in matplotlib?
The default text alignment in matplotlib is left alignment.
How to set the font size in matplotlib?
You can set the font size in matplotlib by using the fontsize
parameter in the plt.xticks()
, plt.yticks()
, plt.xlabel()
, plt.ylabel()
, plt.title()
, and plt.legend()
functions.
Here's an example of how to set the font size for the x-axis ticks:
1 2 3 4 5 |
import matplotlib.pyplot as plt plt.plot([1, 2, 3, 4], [1, 4, 9, 16]) plt.xlabel('x-axis', fontsize=12) plt.show() |
In this example, the fontsize
parameter is set to 12
, which will change the font size of the x-axis label to 12. You can similarly set the font size for other elements like y-axis ticks, title, and legend.