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.

p.i.g.
  • 2,815
  • 2
  • 24
  • 41
David
  • 91
  • 1
  • 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);` – Jim Quirk Dec 12 '14 at 19:47
  • That's some interesting behavior. Thanks for looking into it! – David Dec 17 '14 at 03:29
  • 2
    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. – Matt Jun 11 '15 at 19:33
  • @Matt 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](http://undocumentedmatlab.com/blog/matlab-hg2/). – Dev-iL Jun 17 '15 at 09:56
  • 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. – Numbers682 Jun 09 '17 at 14:52

1 Answers1

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).

NoamG
  • 137
  • 9