Arbitrary colorbar

后端 未结 1 1377
死守一世寂寞
死守一世寂寞 2021-01-07 03:55

I have data that is in the range -70,0 that I display using imshow() and would like to use a non-linear colorbar to represent the data as I have paterns both in the -70,-60

1条回答
  •  北海茫月
    2021-01-07 04:19

    This is what I managed to do:

    import numpy as np
    import matplotlib.pyplot as plt
    from matplotlib.colors import PowerNorm
    sample_data=(np.ones((20,20))*np.linspace(0,1,20)**3)*70-70
    plt.figure()
    im = plt.imshow(sample_data+70, norm=PowerNorm(gamma=0.5))
    cbar = plt.colorbar(orientation='horizontal')
    cbar.ax.set_xticklabels(np.arange(-70, 0, 8))
    plt.show()
    

    You can change the gamma. However, this kind of visualization is not recommended, see: http://matplotlib.org/users/colormapnorms.html under "Power-law" -> "Note"

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