colormap/datatip issue in Matlab figure
Asked Answered
B

1

9

I run this code

A = uint8( ones( 200 ) );
a = [ A * 0 A * 1; ...
      A * 2 A * 3 ];

color_map = [ 0    0    0; ...
              0.3  0.3  0.3; ...
              0.9  0.3  0.1; ...
              1    1    1; ...
              zeros( 252, 3 ) ];

h = image( a );
colormap( color_map );

Then, I select a point in the figure using the datatip feature. This makes the colors in the figure change. They still have the same indices and RBG values, but they are different colors. Then, I delete the datatip, and the colors return to their proper colors.

Using,

set(gcf, 'Renderer', 'opengl')

makes the issue go away, but I'm wondering if there is a way to avoid having to do that? I am using MATLAB R2013b.

Bolling answered 12/12, 2014 at 19:3 Comment(5)
That's a weird one. May not be helpful, but I found that if you define the color_map without the zeros at the end, the colors do not change when using the datatip. color_map2 = [0 0 0;.3 .3 .3;.9 .3 .1;1 1 1]; h = image(a);colormap(color_map2);Masque
That's some interesting behavior. Thanks for looking into it!Bolling
For what it's worth there was no color change in 2015a when I tried your code. Mathworks updated the graphics system in 2014b. So 1 answer may be to update Matlab.Leeleeann
@Leeleeann That, or forcing the old version to use the new graphic engine using feature('usehg2',1) or running MATLAB with the -hgVersion 2 command-line option, as per this UndocumentedMatlab post.Higinbotham
Looks like datatip is obsolete for R2017a. I tried looking it up and all the documentation/questions are old. Even doc datatip comes up with a window that shows datatip is obsolete, FYI.Bays
N
1

This line prevents the behaviour you mentioned above:

set(0, 'DefaultFigureRenderer', 'opengl');

It sets the renderer for all the new figures. You can place that line in the startup.m file.

To learn more about startup file, go to:

http://www.mathworks.com/help/matlab/ref/startup.html

(you basicly generate that file if it does not exist, and put there the code you want to run whenever Matlab starts up).

Nautilus answered 16/7, 2015 at 12:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.