Plot a vertical line using matplotlib

前端 未结 2 1617
别那么骄傲
别那么骄傲 2021-01-13 13:46

I would like to draw a vertical line with Matpotlib and I\'m using axvline, but it doesn\'t work.

import sys
import matplotlib
matplotlib.use(\         


        
2条回答
  •  耶瑟儿~
    2021-01-13 14:31

    Your example is not self contained, but I think you need to replace:

    plt.axvline(x=4)
    

    with:

    ax.axvline(x=4)
    

    You are adding the line to an axis that you are not displaying. Using plt. is the pyplot interface which you probably want to avoid for a GUI. So all your plotting has to go on an axis like ax.

提交回复
热议问题