Tue 02 Jun 2015 11:01:20 PM UTC, comment #5:
This is tricky, but ultimately correct as each function, contourf and colorbar, is doing what it is documented to do. I also don't see that we can change it without introducing an incompatibility with Matlab which will generate further bug reports.
Using the file #32554 that you attached in the following discussion. contourf() colors the entire patch object used to represent a contour based on the Z-level of the lowest point of the contour. In this case the call,
will draw 4 contours and the color will be chosen at Z = 0, 1, 2, 3. When you call contourf() the 'clim' property for the axis gets set to [0, 3]. Any values outside that range are clamped to either the minimum or maximum.
The colorbar() function indicates how data values are mapped to color in the corresponding axis. The colormap you set happens to have entries and is equivalent to "gray(4)". The color axis (caxis() or 'clim' property) runs from 0 to 3 and there are 4 color levels so each break occurs at (3-0)/4 or 0.75. This is indeed what the the colorbar from Matlab and Octave show. Further, the data values do match. The first contour is black, which is the color in the colorbar shown for 0. The second contour is dark grey (z=1), which is the color for any value between 0.75 and 1.5. The third contour is light grey (z=2), which is the color for any value between 1.5 and 2.25. The final contour is white which is the color for any value from 2.25 to Infinity since any value greater than 3 is clamped to 3.
It's perhaps easier to see with this set of commands
which draws contours every 0.5 and shows that each contour is picking up the correct color mapping.
If you are after a particular presentation effect then I would use the longer form of colorbar, 'hc = colorbar', to get a handle to the axes object used to implement the colorbar. Then you can manipulate the properties however you like.
For example,
will produce the picture I think you were hoping for.
|
Mon 01 Jun 2015 02:36:04 PM UTC, comment #4:
I tested it. Matlab has the same bug. But I do INSIST that this is a BUG. When you look at the attached graph below for a little longer (file #32554), you will understand why.
For example: When you look at the isoline with value 3 in the graph, you will notice that this value is right between the colors white and light gray. In contrast, when you look at the colorbar to figure out what value the function has at the border between white and light gray you will find a value of 2.25.
Since the function plotted here is z=y, the isoline-value is obviously correct and the other one is wrong.
Hope this helps.
-Malte
|
Wed 26 Nov 2014 08:05:11 PM UTC, original submission:
Well,
The title says it all. Compare the position of clabels with the colormap ticks and you know what the problem is ;-)
|