bugGNU Octave - Bugs: bug #65674, axes "colormap" property...

 
 

bug #65674: axes "colormap" property being set over figure "colormap" property

Submitter:  Armin Müller <arm_in>
Submitted:  Thu 02 May 2024 07:46:05 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 9.1.0 Operating System:  * Any
Fixed Release:  10.1.0 (current default) Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Mon 13 May 2024 06:47:47 PM UTC, comment #10: 

It turns out that Matlab changed the behavior of the colormap() function starting with R2018a.  Applying a colormap to a figure object (the default) now automatically removes any colormaps applied to axes objects.  I made the same change for Octave in this changeset https://hg.savannah.gnu.org/hgweb/octave/rev/805844e7ff9f.

This change was made on the development branch (future 10.1 release), but you can always just download the m-file from the Mercurial repository if you want the change immediately.

Marking bug as Fixed and closing report.

Rik <rik5>
Group administrator
Sun 05 May 2024 09:28:59 AM UTC, comment #9: 

Good analysis!

Yes, the built-in demo images differ between Matlab and Octave. rand() will always work.

Armin Müller <arm_in>
Sat 04 May 2024 05:14:24 PM UTC, comment #8: 

It seems that the issue is probably in the file imshow.m which has statements like


colormap (gca,  arg);


I think just deleting the 'gca' will make this work compatibly.



Rik <rik5>
Group administrator
Sat 04 May 2024 05:09:47 PM UTC, comment #7: 

If I try your example code in Matlab I get an error about "default.img" being undefined.  However, I did find this minimum working example:


clf;
imshow (rand (100, 100));
colormap (autumn (64));


The result should be yellows and oranges, but in Octave is black and white.

Changing Item Group to Matlab Compatibility, re-opening report, and marking as Confirmed.

The issue is that the "colormap" property used to only be a property of figures, but then Matlab went and extended that to axes objects.  If the axes "colormap" property is set, it overrides the figure property version.  Apparently, imshow() in Octave is setting the axes version rather than the figure's version.  You can see this by deleting the axes version with


set (gca, 'colormap', [])


which will then cause the image to display in yellow/orange.

Rik <rik5>
Group administrator
Sat 04 May 2024 04:56:59 PM UTC, comment #6: 

Type. I mean:

clf;
imshow ("default.img");
colormap (gca, autumn (64));


Armin Müller <arm_in>
Sat 04 May 2024 04:55:38 PM UTC, comment #5: 

Thanks to everybody for the workarounds and for the additional explanations!

The original "Demo 2" will work fine if "gca" added:


clf;
imshow ("default.img");
colormap (autumn (64));


This is uncommon, since gca can usually be omitted if there is just one graphics object contained in a figure. The call to colormap() will most problably go to waste instead of refering to the most recent axis object.

Nevertheless, I don't think it is "simply invalid code" on my side.
It is working on Matlab, so the bug may also be grouped as "Matlab compatibility".

Armin Müller <arm_in>
Fri 03 May 2024 05:29:31 PM UTC, comment #4: 

Documentation on SourceForge is out-of-date and should not be used.  Within Octave 9.1, try demos 4 and 5 from imshow.


octave:2> demo imshow 5
imshow example 5:
 clf;
 imshow (rand (100, 100));
 title ({"imshow with random 100x100 matrix", "black and white"});

octave:3> demo imshow 6
imshow example 6:
 clf;
 imshow (rand (100, 100));
 colormap (gca, jet (64));
 title ({"imshow with random 100x100 matrix", "colormap() makes color image"});


The image will update as the colormap is changed.

Closing bug report as this is simply invalid code for recent versions of Octave.

Rik <rik5>
Group administrator
Fri 03 May 2024 04:27:50 PM UTC, comment #3: 

Use imagesc not image or imshow

Anonymous
Fri 03 May 2024 01:41:19 PM UTC, comment #2: 

I couldn't fully reproduce this with dev Octave (10.0.0) on Windows.
That is, I also saw nothing happen after 'colormap (autumn (64));', but next when I tried 'clf; sombrero' the picture was in colormap 'autumn' (that is, in brownish and reddish colors rather than blueish). But I couldn't reproduce that again.

So maybe colormap only works before creating the figure (or rather, the axes)? (unsure if this is intended.)

Philip Nienhuis <philipnienhuis>
Group Member
Thu 02 May 2024 09:01:30 PM UTC, comment #1: 

imagesc instead of imshow

Anonymous
Thu 02 May 2024 07:46:05 PM UTC, original submission:  

No matter what I do, the image is always shown in grayscale.

Windows 10
Octave 9.1.0

also with Octave online
https://octave-online.net/

Own example:


x=rand(10,10);

figure(1)
imshow(x)
colormap jet
colorbar


figure(2)
imshow(x)
colormap('jet')
colorbar


figure(3)
imshow(x)
colormap(jet(32))
colorbar



Demo 2 from Octave help also won't work
https://octave.sourceforge.io/octave/function/imshow.html


clf;
imshow ("default.img");
colormap (autumn (64));


Armin Müller <arm_in>

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by arm_in (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 11 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-05-13 rik5 StatusConfirmed Fixed
        Open/ClosedOpen Closed
        Fixed ReleaseNone 10.1.0 (current default)
    2024-05-04 rik5 Item GroupIncorrect Result Matlab Compatibility
        StatusInvalid / Not an Octave Bug Confirmed
        Open/ClosedClosed Open
        Operating SystemMicrosoft Windows Any
        Summarycolormap() does nothing axes "colormap" property being set over figure "colormap" property
    2024-05-03 rik5 CategoryNone Octave Function
        StatusNone Invalid / Not an Octave Bug
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code