Reputation: 429
I have built a plotter GUI with which I can load data files, choose independent/dependent variables, and plot multiple lines. Right now, when it overplots multiple lines, it just cycles through the Matlab default color order with the solid line type.
I want to add several popup menus to my GUI to assign different colors and line types (even line width) to different curves like the Matlab Plot Tool shown below (of course, not as fancy as this).
For some reason, I can't attach an image to show the Matlab Plot Tool, but basically there are bunch of popup menus (aka drop-down menu) with line type, line width, and line color; and also marker type, marker size, and marker color.
How should I go about this? I cannot use GUIDE since the dimensions of and the options on the GUI change with different data file types or parameter types contained in them. It's a varying GUI while you are stuck with a GUI made by GUIDE (at least, that's my understanding).
Upvotes: 1
Views: 1458
Reputation: 12214
The default MATLAB color selection box can be called using uisetcolor
, which returns an RGB triplet. If you specify an output to plot
you can modify the properties of your plotted line(s) without having to replot. You can use the RGB triplet returned by uisetcolor
in a call to set
and modify the 'Color'
of your plot.
Here is a generic example using a programmatic GUI:
function testcode
% Initialize GUI
handles.myfig = figure('MenuBar', 'none', ...
'Name', 'Sample GUI', ...
'NumberTitle', 'off', ...
'ToolBar', 'none', ...
'Units', 'Pixels', ...
'Position', [400 200 800 600] ...
);
handles.myaxes = axes('Parent', handles.myfig, ...
'Units', 'Normalized', ...
'Position', [0.35 0.1 0.6 0.8] ...
);
handles.myplot = plot(handles.myaxes, 1:10); % Plot dummy data
handles.colorbutton = uicontrol('Parent', handles.myfig, ...
'Style', 'pushbutton', ...
'Units', 'Normalized', ...
'Position', [0.05 0.1 0.2 0.8], ...
'String', 'Change Color' ...
);
set(handles.colorbutton, 'Callback', {@changecolor, handles});
end
function changecolor(~, ~, handles)
rgb = uisetcolor();
set(handles.myplot, 'Color', rgb);
end
The process will be more or less the same for a GUIDE GUI along with making your own dropdowns for other line properties. You may also want to reference MATLAB's documentation for Sharing Data Among Callbacks.
Upvotes: 1
Reputation: 1110
Generally speaking, I am not sure it is a problem with GUI. In order to change the plot properties, you can check the plot properties documentation.
http://www.mathworks.com/help/matlab/ref/chartline-properties.html
For example, you can plot with dashed line like this :
plot(1:10, 'LineStyle', '--');
Upvotes: -1