Can't display several fill plots in UIAxes in App

3 次查看(过去 30 天)
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

回答(2 个)

Ninad
Ninad 2024-6-24
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:
  1. The "hold(ax, 'on')" command is used to ensure that all plots are held on the UIAxes specified by ax.
  2. The "fill" function is called with the "ax" handle as the first argument to ensure that the polygons are plotted on the correct axes.
I have also initialized the variables "tbl", "zeroStart", "duration", and "level" with sample values, for sake of completeness.
Hope this helps!
Regards,
Ninad

Shreshth
Shreshth 2024-6-24
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.

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by