bugGNU Octave - Bugs: bug #43705, wrong position of ticks on colormap

 
 

bug #43705: wrong position of ticks on colormap

Submitter:  None
Submitted:  Wed 26 Nov 2014 08:05:11 PM UTC
   
 
Category:  Plotting Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Wont Fix Assigned to:  None
Originator Name:  Malte Hinrichs Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 3.8.0
Operating System:  * Mac OS Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

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 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,


c=contourf(mX, mY, mF, [0:3]);


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


c=contourf(mX, mY, mF, [0:0.5:3]);
clabel (c)
colorbar


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,


close all
colormap (gray (4));
[X,Y] = meshgrid (0:0.1:4);
Z = Y;
c = contourf (X, Y, Z, [0:3]);
clabel (c)
hc = colorbar;
set (hc, "ytick", [0:0.75:3], "yticklabel", {"0", "1", "2", "3"})


will produce the picture I think you were hoping for.

Rik <rik5>
Group administrator
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 , 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


Malte Hinrichs <maldje>
Tue 19 May 2015 03:35:42 PM UTC, comment #3: 

Can you run the sample code in Matlab and produce a second snaphsot?  It's not clear that the colorbar and the contour will look the same if the caxis values are different.  Can you also execute caxis() and report what it returns.

Rik <rik5>
Group administrator
Sun 07 Dec 2014 03:07:52 PM UTC, comment #2: 


I am not sure when I will have access to matlab.

However, the result must be that the numbers on the very right (color bar) are identical and at the same y-coordinate as to those on the very left (y-axis).

-Malte



Malte Hinrichs <maldje>
Sat 06 Dec 2014 09:10:13 PM UTC, comment #1: 

Do you have access to Matlab and could you run the equivalent code there to produce a second snapshot?  I would like to know what the goal should look like.

Rik <rik5>
Group administrator
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 ;-)


%define a simple function
vx=[0:0.1:4];
vy=vx;
[mX mY]=meshgrid(vx,vy);
mF=mY;

% define a short colormap
cm=linspace(0,1,4)';
colormap([cm cm cm])

c=contourf(mX, mY, mF, [0:3]);
clabel(c)
colorbar;

print -dpng bug_colormap.png


Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #32554:  bug_colormap.png added by None (16KiB - image/png)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by maldje (Posted a comment)
  • -email is unavailable- added by rik5 (Updated the item)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-06-02 rik5 StatusNeed Info Wont Fix
        Open/ClosedOpen Closed
    2014-12-06 rik5 StatusNone Need Info
    2014-11-26 None Attached File- Added bug_colormap.png, #32554

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code