Draw axis lines or the origin for Matplotlib contour plot

前端 未结 2 547
走了就别回头了
走了就别回头了 2021-02-03 23:36

I want to draw x=0 and y=0 axis in my contour plot, using a white color. If that is too cumbersome, I would like to have a white dot denoting where th

相关标签:
2条回答
  • 2021-02-03 23:51

    There are a number of options (E.g. centered spines), but in your case, it's probably simplest to just use axhline and axvline.

    E.g.

    import numpy as np
    import matplotlib.pyplot as plt
    
    xvec = np.linspace(-5.,5.,100)                               
    x,y = np.meshgrid(xvec, xvec)
    z = -np.hypot(x, y)                                
    
    plt.contourf(x, y, z, 100)                             
    plt.colorbar() 
    
    plt.axhline(0, color='white')
    plt.axvline(0, color='white')
    
    plt.show()
    

    enter image description here

    0 讨论(0)
  • 2021-02-04 00:17

    Can't you just overlay a straight line?

    plt.plot([0,0],[-4,4],lw=3,'w')
    
    0 讨论(0)
提交回复
热议问题