1

I'm plotting both a line and some scatter points on the line. I want to label the x-coordinate of the scatter points on the line, and the annotations are being obstructed by the line. Without manually inputting the position of the annotations, is there a way to shift all of the annotation texts to the right by a certain amount?

Below is part of the code to produce the scatter plot and annotation.

import numpy as np
import matplotlib.pyplot as plt
fs = 20
figure, ax1 = plt.subplots()
ax1.set_xlim(1.6, 2.0)
ax1.set_ylim(-2, 5)
annotations = ['$1.66$', '$1.68$', '$1.72$', '$1.74$', '$1.76$']
xpoint = [1.66, 1.68, 1.72, 1.74, 1.76]
ypoint = [3.47072347e-01, 5.05186795e+00, 1.61807901e+01, 5.60855544e+01, 6.07027325e+02]
ax1.scatter(xpoint, np.log10(ypoint), color='k')
for i, label in enumerate(annotations):
    ax1.annotate(label, (xpoint[i], np.log10(ypoint[i])), ha='left', va='center', fontsize=fs)

ax1.tick_params(labelsize=fs)
figure.savefig("plot.svg", bbox_inches='tight')

enter image description here

liuyun
  • 111
  • 1
  • There are ways to do this, but the easiest is to just add spaces at the front of each string. `annotations = ['. $1.66$', ' $1.68$', ...]` – Jody Klymak Jun 08 '22 at 15:22

0 Answers0