Adding Callback to stackedplot

3 views (last 30 days)
Maximilian Schulte
Maximilian Schulte on 7 Apr 2024
I'm currently writing a class that is using a stackedplot to display a selected rows of a Timetable. You are loading a big Timetable into the stackedplot, after that you can set the rows of the timetable that will be displayed via a gui. The problem is, that once it's set you can not recall the gui to set the DisplayVariables of the stackedplot again. Is there any way to add a callback to my class or the stackedplot so that i cann call the function that recalls the gui.
Options i already thougt of were either adding a tool to the axis toolbox or working with listeners, but i couldn't get any of those to run.

Answers (1)

Pratyush
Pratyush on 8 Apr 2024
Hi Maximilian,
I guess one straightforward way to achieve this is by adding a UI control (e.g., a button) to your figure that, when clicked, invokes the GUI for selecting "DisplayVariable".
Here is an example script that may help.
function createInteractiveStackedPlot(TT)
% Create a figure
f = figure;
% Create a stacked plot
sp = stackedplot(TT);
% Add a button for adjusting DisplayVariables
btn = uicontrol('Style', 'pushbutton', 'String', 'Change Variables',...
'Position', [20 20 150 20],...
'Callback', @changeDisplayVariables);
function changeDisplayVariables(src, event)
% Callback function to invoke GUI for changing DisplayVariables
% Here, you would implement or call your GUI for selecting variables
disp('Implement your GUI logic here');
% Example: Update DisplayVariables (You'll replace this with GUI logic)
sp.DisplayVariables = TT.Properties.VariableNames(randperm(width(TT), 3));
end
end
  1 Comment
Maximilian Schulte
Maximilian Schulte on 8 Apr 2024
Thanks, i also think that implementing this will be quite easy as you said, but i'd love to have a cleaner solution regarding optical apperance. I also thougt of adding a context menu but that did not work either

Sign in to comment.

Categories

Find more on Line Plots in Help Center and File Exchange

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!