plotting markers on top of axes

后端 未结 3 559
生来不讨喜
生来不讨喜 2021-02-08 01:15

I am tying to make a (x,y) scatter plot using numpy. Right now the axes start from (0,0) and extend to align with the range of the data. I need to plot two points which lie on

相关标签:
3条回答
  • 2021-02-08 01:32

    To actually make the markers appear on top of the axes, you can use zorder:

    import numpy as np
    import matplotlib.pyplot as plt
    x = np.array([0,1,2,3,4,5,6])
    y = np.array([0,2,0,4.5,0.5,2,3])
    
    plt.plot(x, y, 'o', zorder=10, clip_on=False)
    plt.xlim(0, 6)
    plt.ylim(0, 4.5)
    plt.show()
    

    The result

    0 讨论(0)
  • 2021-02-08 01:35

    You can turn off the clip flag of the line object created by plt.plot.

    import numpy as np
    import matplotlib.pyplot as plt
    x = np.array([0,1,2,3,4,5,6])
    y = np.array([0,2,0,4.5,0.5,2,3])
    
    line = plt.plot(x,y,'o')[0]
    line.set_clip_on(False)
    plt.show()
    

    enter image description here

    0 讨论(0)
  • 2021-02-08 01:43

    I think you're after plt.axis([xmin,xmax,ymin,ymax]):

    import numpy as np
    import matplotlib.pyplot as plt
    x = np.array([0,1,2,3,4,5,6])
    y = np.array([0,2,0,4.5,0.5,2,3])
    plt.plot(x,y,'o')
    plt.axis()
    # (0.0, 6.0, 0.0, 4.5)
    plt.axis([-.5,6.5,-.5,5])
    plt.show()
    

    enter image description here

    You could programatically retrive the current axis with plt.axis() and then subtract/add a small margin on, and re-set it.

    0 讨论(0)
提交回复
热议问题