Is it possible to anchor a matplotlib annotation to a data coordinate in the x-axis, but to a relative location in the y-axis?

前端 未结 1 1900
南笙
南笙 2020-12-06 17:14

I have a plot where I\'d like to annotate a specific location on the x-axis with an arrow and a label:

  • The location of the tip of the arrow needs to be specifi
相关标签:
1条回答
  • 2020-12-06 18:05

    Pass the transformation to the xycoords and textcoords parameters instead of to the transform parameter. Like so:

    fig, ax = make_example_plot()
    tform = blended_transform_factory(ax.transData, ax.transAxes)
    ax.annotate(label, xy=(r, 0), xycoords=tform, 
                xytext=(r, 0.9), textcoords=tform, fontsize='xx-large',
                ha='center', va='center', color='r', arrowprops=arrowprops)
    
    0 讨论(0)
提交回复
热议问题