Positioning text by axis fraction

前端 未结 1 1833
不思量自难忘°
不思量自难忘° 2021-01-15 13:44

Is there a way to position text in a figure by the fraction of the axis? I want the text in the same position for all my plots regardless of their differing ranges in x and

相关标签:
1条回答
  • 2021-01-15 14:34

    You can use the transform keyword:

    import matplotlib.pyplot as plt
    import numpy as np
    
    fig = plt.figure() 
    ax = fig.add_subplot(1, 1, 1)
    ax.plot(np.arange(10),12*np.arange(10)) 
    ax.text(0.4, 0.7, 'Correct Position', transform=ax.transAxes)
    
    plt.show()
    
    0 讨论(0)
提交回复
热议问题