Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab How to use a suitable color bar?

  1. Mar 9, 2016 #1

    kelvin490

    User Avatar
    Gold Member

    I have a picture which shows the magnitude of some value in terms of color, like this one:

    https://www.dropbox.com/s/yoh0n9cqftvrtlz/bar.jpg?dl=0

    The higher the magnitude, the more it looks red. However there are only a few points at the edge has very high values and most of the points have much lower values. If a colorbar with equal intervals is used the picture just looks blue throughout and the values in most areas cannot be distinguished.

    Is it possible to set a colorbar that has, say, exponentially increasing intervals (or others) so that the center part can also show different colors?
     
  2. jcsd
  3. Mar 9, 2016 #2

    DrClaude

    User Avatar

    Staff: Mentor

    I don't know of a way to ask Matlab to use a non-linear color scale, but you can remedy the problem by plotting, for instance, the log of your data instead of the raw data itself.
     
  4. Mar 9, 2016 #3

    kelvin490

    User Avatar
    Gold Member

    Readers are usually more comfortable with un-scaled data. Many other posts only offers solutions which requires scaling the data, but rescaling the colorbar without altering the data is more preferable. Thanks though.
     
  5. Mar 9, 2016 #4

    DrClaude

    User Avatar

    Staff: Mentor

    One possibility is of course to use other software. I, for instance, use Igor Pro for plotting, and it does log color scaling.

    Looking around, I found the following: http://ww.mathworks.com/matlabcentral/newsreader/view_thread/152310 [Broken]

    The third message, dated 20 Jul, 2007 17:12:42, has a workaround.
     
    Last edited by a moderator: May 7, 2017
  6. Apr 2, 2016 #5

    kreil

    User Avatar
    Gold Member

    It looks like the figure is washed out at the bottom (blue), so you'll want to use a smaller max value. You'll want to play with the colorbar limits to find where the "interesting" range is, i.e. where the bottom values clipping to dark blue and the top values clipping to bright red are somewhat equalized.

    You can change the colorbar limits this way (this example goes to 0.15 instead of 0.35, about half the range):

    Code (Text):

    % Get a handle to the current figure object
    ax = gca;

    % Adjust the CLim property to use a different range of values for the colorbar.
    % Scaled by 1e4 since it seems you use this scaling in your plot.
    ax.CLim = 1e4*[0, 0.15];
     
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted