Some Research
Thanks to OP’s question I have learnt something new today. So, I knew that one can change the XColor of the axes by code too, with the command – set(handles.axes1,'XColor',colorname)
, where colorname
could be any color, like ‘r’ for red, ‘k’ for black, etc. So, I would have suggested to use set(handles.axes1,'XColor',’w’)
, but then one has to remember what XColor
was set through GUIDE
and copy over that information to the associated M-file, which isn’t “elegant enough”.
My initial idea was to extract that XColor
info from Fig-file at the initialization stage of the GUI, which is at GUINAME_ OpeningFcn
, save it into the handles structure and use it later on in callback functions through the handles again. I tried to call color_data = get(handles.axes1,'XColor')
at the end of this function to get the XColor
info as a three element vector. That didn’t work as it was giving me [1 1 1] which represents the default color white.
Next obvious thing was to put the color_data extracting command at the start of GUINAME_ OpeningFcn
, before handles.output
is set inside that function and it worked! Thus, the conclusion is that handles.output = hObject
is putting at least Color
information to default values.
Back to work
For OP, the steps would be following :
Put this at the start of GUINAME_ OpeningFcn
axes1_XColor = get(handles.axes1,'XColor');
axes1_YColor = get(handles.axes1,'YColor');
handles.axes1_XColor = axes1_XColor;
handles.axes1_YColor = axes1_YColor;
set(handles.axes1,'XColor',handles.axes1_XColor);
set(handles.axes1,'YColor',handles.axes1_YColor);
When plotting inside any function that has handles
as one of the inputs, use the following commands after plot
set(handles.axes1,'XColor',handles.axes1_XColor);
set(handles.axes1,'YColor',handles.axes1_YColor);
Thus, for your example it would be –
axes(handles.axes1); % axes1 is the tag for my graph in GUIDE
time = 0:1/fs:(length(handles.x)-1)/fs;
plot(time,handles.x);
title('Original Signal');
set(handles.axes1,'XColor',handles.axes1_XColor);
set(handles.axes1,'YColor',handles.axes1_YColor);
Let’s hope it works for you, let us know!