3

I am having trouble with the following plot:

enter image description here

created by the following code:

fig, ax = plt.subplots(figsize=(10, 6), dpi=80)
texts = []
for i, data_col in enumerate(data.columns.values):
    ax.plot(data.index, data[data_col], color=tableau20[i], label=data_col)
    texts.append(ax.text(max(data.index), data[data_col][-1], data_col, fontsize=11, color=tableau20[i]))

This is actually very close to the desired output, I am looking for a way to automatically adjust only the y-Position of the text so there will be no overlapping even if the values are changing (so no hard coded offset) What I found is the well working adjustText package from @Phlya, however I don't get the this solution to only adjust the y position, it will always shift the text on the x axis as well.

So this is the output I get with adding the line

adjust_text(texts, ax=ax, only_move=dict(points='y', text='y', objects='y'), autoalign='y')

enter image description here

is there a way to adjust the functions settings or any other way to achieve what i am looking for?

Quastiat
  • 1,164
  • 1
  • 18
  • 37
  • AnchoredText might help you in this regard. You can look into this stack answer: https://stackoverflow.com/questions/7045729/automatically-position-text-box-in-matplotlib – EMT Aug 25 '21 at 08:43

0 Answers0