0

I have some troubles when trying to adapt the values of my data to the colormap intensity. In particular I want to set the min value and the max value in corrispondence of the white and the black color. I tried with colormap(flipud(gray)) that creates the rights scale of colors, but the limits the colorbar shows are [0,2]. If I manually set limit with colorbar('Limits',[0,1]) the colorbar shows correctly the limits but the colormap is now in a scale from white to grey (and not black). How to handle this?

VanBaffo
  • 259
  • 1
  • 2
  • 13

1 Answers1

1

The colormap will automatically be set to the values of your data. Your data is [0 2] in range, therefore its set to that. To do what you want, you need to saturate your colormap, it will mean that it will plot from white to black at [0 1] but it will be just black at [1 2]. In general, this is bad science, you are misleading the reader about the actual value of the surface/image.

However, if you have a genuine reason to do it, then the command is caxis([0 1])

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120
  • You said that colormap automatically set the values... however I have all the edge of a graph with weight equal to 1. When I plot the graph with `plot(...., 'EdgeCData', weights)` I have a colormap ranging from 0 to 2, and the edges are grey. Why? – VanBaffo Mar 05 '19 at 14:10
  • @Alberto what is `max(max(distances(G)))` ? and `max(weights)` ? – Ander Biguri Mar 05 '19 at 14:46
  • The max distances is 4, the max weight is 1. Why do you ask this? – VanBaffo Mar 05 '19 at 18:25
  • @Alberto I have no experience with `graph` objects, but the color limits are generally set up automatically with the input data, so I was trying to understand why you get [0 2] – Ander Biguri Mar 05 '19 at 18:39
  • With `caxis([0 1])` the colormap shows the right colors, but data are in that range. I'm asking: the colorbar object at which data refers to to take the values? – VanBaffo Mar 05 '19 at 19:31
  • @Alberto can you rephrase that question? I do not know what you mean. – Ander Biguri Mar 05 '19 at 19:39
  • If I set the caxis as above, it correctly display the colorbar with the values ranging from 0 to 1, otherwise not. So I'm asking if the colorbar and colormap objects map values not from my edge weights but from other data... – VanBaffo Mar 05 '19 at 19:43
  • @Alberto yes, that was what I was trying to figure out. It should map values from your color data, or so it does with everything else in MATLAB. But as I explained, I have no idea what it does for `graph` objects. This is why I asked you for the values of `graph`. Anyway, it does not matter, you seem to have your solution. – Ander Biguri Mar 05 '19 at 19:48
  • Yes, Thank you! – VanBaffo Mar 06 '19 at 10:52
  • @Alberto consider accepting the asnwer as valid then ;) – Ander Biguri Mar 06 '19 at 11:15