How to use scrollsubplot in a panel in app designer?
Mostra commenti meno recenti
I have a GUI with two panels. One panel is filled with a number of plots after pushing a button. The number of plots can vary, but when this number increases the plots get very squished together and hard to read. I thought I could work around this using the scrollsubplot() function from file exchange, but each time the button is pressed a separate figure is opened. The plots populate the correct areas in the panel, but the scrollbar is located in this new figure. Here is a portion of my code:
PlotInd = 1;
axBrainStO2 = scrollsubplot(4,1,PlotInd);
axBrainStO2.Parent = app.RightPanel;
plot(axBrainStO2,app.timeNIRS,app.BrainStO2,'m-','LineWidth',1.5)
Is there any way to fix this?
4 Commenti
Bjorn Gustavsson
il 2 Set 2022
Phew, sure there is (ought to be...). After a quick look into the function it seems that a new figure is generated on line 196. To get there the variable nextstate has to be the string 'new' and the variable create_axis has to be true. I haven't worked with programming apps, nor panels. If it is possible you could try to step through subplot and see what goes on, just put a debug-stop at the top of scrollsubplot. Then if it is possible you could try to just put the scrollsubplot into a figure instead of a panel, and see if/what that changes.
If I get around to it I'll try to update scrollsubplot with a more current version of subplot as a basis - that might also help.
Careniena Opem
il 2 Set 2022
Modificato: Careniena Opem
il 2 Set 2022
Careniena Opem
il 7 Set 2022
Dolon Mandal
il 20 Set 2023
Instead of using the scrollsubplot function, you can create a single axes object within your panel and update its position dynamically based on the number of plots. Here's an example of how you can modify your code:
% Assuming you have a GUI with a panel named 'RightPanel'
% Calculate the number of rows and columns based on the number of plots
numPlots = 4; % Replace with your actual number of plots
numRows = ceil(sqrt(numPlots));
numCols = ceil(numPlots / numRows);
% Calculate the position of the axes within the panel
plotInd = 1; % Replace with the appropriate plot index
plotPosition = [mod(plotInd-1, numCols)/numCols, floor((numRows-1-(plotInd-1)/numCols))/numRows, 1/numCols, 1/numRows];
% Create the axes within the panel
axBrainStO2 = axes('Parent', app.RightPanel, 'Position', plotPosition);
% Plot the data on the axes
plot(axBrainStO2, app.timeNIRS, app.BrainStO2, 'm-', 'LineWidth', 1.5);
In this modified code, we calculate the number of rows and columns based on the desired layout of the plots. Then, we calculate the position of each plot within the panel using the plot index and the number of rows and columns. The plotPosition variable represents the position of each plot as a normalized value between 0 and 1.
Next, we create an axes object within the panel using the axes function and set its position using the Position property. The Parent property is set to the RightPanel to ensure that the axes is embedded within the panel.
Finally, we plot the data on the axes using the plot function.
You can repeat this code for each plot, updating the plotInd and plotPosition variables accordingly.
With this approach, all the plots will be contained within a single axes object, and you can control their positions and layout within the panel.
Risposte (0)
Categorie
Scopri di più su Annotations in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!