Logarithmic colorbar?

谁说胖子不能爱 提交于 2020-08-11 02:14:47

问题


I have a colormap that I have successfully modified to have the colors logarithmic, creating the dramatic changes I was seeking. However, my colorbar is still stuck correlating the wrong colors to the wrong values.

Here is a picture to help

As you can see, the colormap is logarithmic, but the colorbar isn't. How do I get the colorbar to be logarithmic?

Code:

plt.figure(dpi=plotResoulution)  # resolution
    self._data = self.rmsArray[:, :, plotTimeStep] 
    plt.pcolor(self._data, norm = colors.LogNorm())  
    colors.LogNorm()
    self._color_map = plt.imshow(self._data) 
    # creates colorbar on the side
    plt.colorbar().ax.set_ylabel('RMS meters of separation', rotation=270, labelpad = 20)
    plt.xlabel("Track")  
    plt.ylabel("car")  
    plt.title(filename + "_TS-" + str(plotTimeStep))  
    plt.savefig(filename + "_TS-" + str(plotTimeStep) + '.png', bbox_inches='tight')
    plt.show()  

As you can see, I have the code norm = colors.LogNorm() but that doesn't change the colorbar, and thus the colors are off with the values.


回答1:


The answer to the question below would help (this seems to be a duplicate question though);

A logarithmic colorbar in matplotlib scatter plot

Matplotlib also has a dedicated section for colormap normalization;

https://matplotlib.org/users/colormapnorms.html

For your question, you would want to use stored value like following;

pcm = plt.pcolor(self._data, norm = colors.LogNorm())

plt.colorbar(pcm)


来源:https://stackoverflow.com/questions/57246146/logarithmic-colorbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!