matplotlib text
时间: 2023-09-09 19:14:14 浏览: 88
Matplotlib's `text` function allows you to add text in a plot at specified coordinates. Here's an example of how you can use it:
```python
import matplotlib.pyplot as plt
# Create a simple plot
x = [1, 2, 3, 4, 5]
y = [1, 4, 9, 16, 25]
plt.plot(x, y)
# Add text at coordinates (3, 15)
plt.text(3, 15, "Sample Text", fontsize=12, color='red')
# Customize the text appearance
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.title("Plot with Text")
# Display the plot
plt.show()
```
In this example, the `text` function is used to add the text "Sample Text" at coordinates (3, 15) on the plot. You can also specify additional parameters such as `fontsize` and `color` to customize the appearance of the text.
阅读全文