Matplotlib vline label parameter not showing

后端 未结 3 1824
再見小時候
再見小時候 2021-02-20 03:32

I want to label my vertical lines with matplotlib\'s .vline command, but for some reason the label parameter doesn\'t do anything/show anything on the final plot. Does anyone kn

3条回答
  •  北恋
    北恋 (楼主)
    2021-02-20 03:47

    For text near your line as in this example use:

    vline_value = 3
    
    fig, ax = plt.subplots(figsize=(10,10))
    ax.axvline(x=vline_value, ymin=0, ymax=1) 
    x_bounds = ax.get_xlim()
    ax.annotate(s='vline_value', xy =(((vline_value-x_bounds[0])/(x_bounds[1]-x_bounds[0])),1.01), xycoords='axes fraction', verticalalignment='right', horizontalalignment='right bottom' , rotation = 270)
    fig.savefig('example')
    

    Also, this short script holds more options if you want: https://pythonhosted.org/lineid_plot/#

提交回复
热议问题