Matplotlib Text

import matplotlib.pyplot as plt

# Sample data
x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 7, 11]

# Create a plot
plt.plot(x, y, marker='o')

# Add text inside the plot
plt.text(2, 6, "Important Point", fontsize=12, color='red')

# Display the plot
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Simple Text Inside a Plot')
plt.show()
import matplotlib.pyplot as plt

# Sample data
x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 7, 11]

# Create a plot
plt.plot(x, y, marker='o')

# Add customized text inside the plot
plt.text(3, 5, "Prime Number", fontsize=14, color='green', fontweight='bold', ha='center', va='bottom', rotation=45)

# Display the plot
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Customized Text Inside a Plot')
plt.show()
import matplotlib.pyplot as plt

# Sample data
x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 7, 11]

# Create a plot
plt.plot(x, y, marker='o')

# Add annotation to highlight a specific data point
plt.annotate('Highest Value', 
             xy=(5, 11), 
             xytext=(3, 10), 
             arrowprops=dict(facecolor='black', shrink=0.05))

# Display the plot
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Annotation Inside a Plot')
plt.show()
import matplotlib.pyplot as plt
import numpy as np

# Create some data
x = np.linspace(0, 10, 100)
y = np.sin(x)

# Basic plot
plt.plot(x, y)

# Add multiple pieces of text and annotations
plt.text(2, 0.5, 'First Peak', fontsize=12, color='blue')
plt.annotate('Second Peak',
             xy=(3*np.pi/2, np.sin(3*np.pi/2)), xycoords='data',
             xytext=(3*np.pi/2, np.sin(3*np.pi/2) - 0.5), textcoords='data',
             arrowprops=dict(facecolor='black', shrink=0.05))

plt.text(7, 0.5, 'Third Peak', fontsize=12, color='green')
plt.annotate('Fourth Peak',
             xy=(2*np.pi, np.sin(2*np.pi)), xycoords='data',
             xytext=(2*np.pi, 1), textcoords='data',
             arrowprops=dict(facecolor='red', shrink=0.05))

# Display the plot
plt.show()