I am trying to create a scatter plot. I want to place two lines of text: PP=0.87 and SC=0.76. Now whenever I'm entering some text in the code it is placed in the bottom left corner of the curve instead of the top right please tell me what I should do.
What I'm getting: https://i.stack.imgur.com/r2wH3.png
I'm expecting in two lines: https://i.stack.imgur.com/P5d81.jpg
My code:
import numpy as np
import matplotlib.pyplot as plt
x = [6,9,4,7,3]
y = [4,9,3,5,3]
plt.text(-0.5, -0.25, 'PP=0.87 \n SC=0.76')
plt.scatter(x, y, c = 'k')
plt.show()
plt.text
uses data coordinates by default. You can use axis coordinates like this:
plt.text(0.5, 0.25, 'PP=0.87 \n SC=0.76', transform=plt.gca().transAxes)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With