Why does my text not retain its color when I turn my axes off?

1 view (last 30 days)
Here is code that shows this behavior:
%With axis=off white areas which are displayed
% correctly on screen
%are printed in black independently of devicetype.
%(Error at least since version 5.0)
%
clear all;
X0=5; Xa=X0+1;
Y0=5; Ya=Y0+1;
figure(1);
clf;
h1=fill([-X0 X0 X0 -X0 -X0],[-Y0 -Y0 Y0 Y0 -Y0],'r');
set(h1,'EdgeColor','r');
h2=text(0,0,'TEST');
set(h2,'VerticalAlignment','middle',...
'HorizontalAlignment','center');
axis([-Xa Xa -Ya Ya]);
set(h2,'FontSize',64,'Color','w');
%example 1: with axis=on -> no error
print -dpsc2 compl001
%example 2: with axis=off -> printed figure erroneous !!!!!!!!!!!!!
% white text changes to black text !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
axis off
print -dpsc2 -append compl001
%change white color slightly
w = [254 255 255]/255;
set(h2,'Color',w);
%example 3: with axis=on -> no error
axis on;
print -dpsc2 -append compl001
%example 4: with axis=off -> no error
axis off
print -dpsc2 -append compl001

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This is expected behavior.
If the figure's "InvertHardCopy" property is set to 'on', the code looks to see what the printed color of the object's container and the object's color will be (note that the axes is usually the container for the image but when the axes is "off", the figure canvass / background becomes the container). If the container's printed color will be white and the object is currently white then it sets the object's color to black (hoping to provide a contrasting color against the container's printed color). The code does not look at how the objects within a container are positioned relative to one another.
In other words, in this particular case, the fact that the patch serves as a red "background" for the text object isn't something that the code is aware of. The only consideration is that, since the axes is off, the figure serves as the background for all objects in the axes. Thus, since the figure background will be set to white then anything white in the axes needs to be converted to black.
As a workaround, below are a couple of suggestions:
1. Set the InvertHardCopy property to "off" and the background color of the figure to "white" as follows:
set(gcf,'InvertHardCopy','off', 'Color','white');
2. Alternatively, you could also set the text color to something close to white as opposed to the [1 1 1] RGB color index.

More Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Products


Release

R2006b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!