- The "hold(ax, 'on')" command is used to ensure that all plots are held on the UIAxes specified by ax.
- The "fill" function is called with the "ax" handle as the first argument to ensure that the polygons are plotted on the correct axes.
Can't display several fill plots in UIAxes in App
4 views (last 30 days)
Show older comments
Hello,
When I'm trying to plot several fill plot in UIAxes, it plots only the last one.
when trying to plot using text(), plot(), it works well.
for i = 1:height(tbl)
hold on
x = [zeroStart(i),zeroStart(i) + duration(i),zeroStart(i) + duration(i),zeroStart(i)];
y = [2*level(i)-0.25,2*level(i)-0.25,2*level(i),2*level(i)];
ff(i) = fill(x,y,colors(end-level(i),:))
end
Would appreciate help,
Thanks
0 Comments
Answers (2)
Ninad
on 24 Jun 2024
Hi Mark,
This issue is likely because "hold on" is not being applied correctly within the loop, or there might be an issue with the plotting context in the UIAxes.
I have attached a dummy code "fillScript.m" that should help you with this with the following changes:
I have also initialized the variables "tbl", "zeroStart", "duration", and "level" with sample values, for sake of completeness.
Hope this helps!
Regards,
Ninad
0 Comments
Shreshth
on 24 Jun 2024
Hey Mark,
It looks like you are trying to plot multiple fill plots within a loop, but only the last one is being displayed.
One way in which you can try solving is instead of using a loop to create all the fill plots at once, create each fill plot individually within the loop. Here’s an example of how you can modify your code:
function GraphButtonPushed(app, event)
x = str2num(app.Valuesx.Value);
cla(app.UIAxes); % Clear the UIAxes
for i = 1:height(tbl)
hold(app.UIAxes, 'on'); % Hold on for subsequent plots
x_vals = [zeroStart(i), zeroStart(i) + duration(i), zeroStart(i) + duration(i), zeroStart(i)];
y_vals = [2*level(i) - 0.25, 2*level(i) - 0.25, 2*level(i), 2*level(i)];
fill(app.UIAxes, x_vals, y_vals, colors(end - level(i), :));
end
end
In this modified code, each fill plot is created within the loop, and the UIAxes is held on for subsequent plots.
Make sure that the UIAxes is correctly set up in your app. You can create the UIAxes using uiaxes(fig) (where fig is the parent figure) and then use the fill function to add the fill plots.
Hoep it helps.
0 Comments
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!