Python/Matplotlib - Colorbar Range and Display Values

前端 未结 1 2022
一整个雨季
一整个雨季 2020-12-23 16:56

When using matplotlib with a contour plot, I\'m having trouble getting the colorbar to display as I want. I\'ve read through numerous similar examples, but have still not

相关标签:
1条回答
  • 2020-12-23 17:40

    If I understand correctly what you want, I think this should do it:

    import numpy as np
    import matplotlib.pyplot as plt
    
    xi = np.array([0., 0.5, 1.0])
    yi = np.array([0., 0.5, 1.0])
    zi = np.array([[0., 1.0, 2.0],
                   [0., 1.0, 2.0],
                   [-0.1, 1.0, 2.0]])
    
    v = np.linspace(-.1, 2.0, 15, endpoint=True)
    plt.contour(xi, yi, zi, v, linewidths=0.5, colors='k')
    plt.contourf(xi, yi, zi, v, cmap=plt.cm.jet)
    x = plt.colorbar(ticks=v)
    print x
    plt.show()
    

    enter image description here

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