🚀 Gen 5 of the leading AI app deployment platform launches October 6. Click for the livestream.

How to align the vline and hline annotations to the lines?

Hey guys,

I’m trying to create a chart design where it has two lines that are drawn based on the mean of the x and y of the blue points;

You can see the chart design below:
image




As I have 4 different figures on it, I’m getting the mean of x and y of the second figure to draw these lines by:

    hline_n=fig.data[1]["y"].mean()
    vline_n=fig.data[1]["x"].mean()

And drawing the lines by this snippet code:


    # Draw the lines on the chart
    fig.add_hline(y=hline_n, line_width=2,  
                line_color="#7F8194",
                  annotation=dict(font_size=14),
                  annotation_text=f"<b>{round(hline_n*100,2)}</b>",
                  annotation_position="right")
    
    fig.add_vline(x=vline_n, line_width=2, 
                    line_color="#7F8194", 
                    annotation=dict(font_size=14),
                    annotation_text=f"<b>{round(vline_n*100,2)}<b>",
                    annotation_position="top")
    

The problem I’m facing is that the text annotation isn’t being set correctly on the top of the line; As shows in the image below:

I suspect that it’s being caused because of the type=“log” on the x-axis, but I’m not understanding why the line is being correctly set but the text not;

What should I change to fix this problem?

Below are the arguments of the annotations:

(layout.Annotation({
     'font': {'size': 14},
     'showarrow': False,
     'text': '<b>11.98</b>',
     'x': 1,
     'xanchor': 'left',
     'xref': 'x domain',
     'y': 0.11980875631799615,
     'yanchor': 'middle',
     'yref': 'y'
 }),
 layout.Annotation({
     'font': {'size': 14},
     'showarrow': False,
     'text': '<b>5.02<b>',
     'x': 0.05015817387759197,
     'xanchor': 'left',
     'xref': 'x',
     'y': 1,
     'yanchor': 'top',
     'yref': 'y domain'
 }))

If you need any extra information, please let me know!!!

Any help is very welcome!

Regards,
Leonardo