0

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.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • You have one `plt.pcolor`, which is logarithmic, and you have one `plt.imshow`, which is not logarithmic (because no norm is explicitely set). The colorbar is produced for the last of those, so it's not logarithmic either. Solution: Don't create two image plots in the same axes! – ImportanceOfBeingErnest Jul 29 '19 at 01:40

1 Answers1

2

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)
Jin
  • 304
  • 2
  • 10