Not able to view legend in Axes handle using report generator toolbox
Show older comments
Hello Folks,
I am facing an issue using Axes handle in Report Generator toolbox.
First of all I am generating "axis handle" in MATLAB Application GUI. This is being used as input to one of the function in takes this axis handle and converts to report dom compliable "Axes Handle".
My problem is that in "axis handle" as well as "Axes Handle" in both this I am able to view their legends in properties stored. When I am appending it to a report these legend are not visibile.
This is a small part of code which I am using.
% Function used to generate report
GenerateReport(vargain)
% Inside the function
axh1 = Axes(varargin{1});
append(ch1,axh1)
append(rpt,ch1)
Here are the sample figures.
This is the "axis handle" which I am able to see when this figure is generated.

And this is the figure which is being seen in report. This is the snapshot of report generated.

This is the properties which I am able to see in "axh1.Source.Legend.String"

If you see in the ablove figure these legend are stored in String format in "Axes Handle" properties.
My problem is that how to add these legends in the "Axes Handle" ?
Any ideas would be appriciated.
Thanks in Advance.
Accepted Answer
More Answers (1)
Yash
on 20 Oct 2023
Hi Jay,
I understand that you are unable to view the legend of a figure when it is added to a report generated using the "Report Generator" toolbox. Instead of appending the "Axes Handle" to the "Chapter" object, set the legend of the plot with the values "axh1.Source.Legend.String" using the "legend()" function and append the plot to the chapter. Please refer to the documentation provided below for more information on "legend()" function: https://www.mathworks.com/help/releases/R2021b/matlab/ref/legend.html. Consider updating the code in the following manner:
% Inside the function
axh1 = Axes(varargin{1});
% figure plotting
fig = figure(gcf);
ax = gca;
% xData is x axis data of size 1xN
% yData is y axis data of size pxN
% N is number of data points
% p is number of plots
plot(ax, xData, yData);
% set legend
legend(axh1.Source.Legend.String);
append(ch1,fig); % fig is the figure window
append(rpt,ch1);
Alternatively, generate the plot and save it as a image and add the image to the report
% Inside the function
fig = figure(gcf);
ax = gca;
x = linspace(0,5);
y1 = sin(x/2);
y2 = cos(x/2);
y = [y1;y2];
% generate plot
plot(ax,x,y);
str = ['sin(x/2)';'cos(x/2)'];
legend(str);
% save plot as image
saveas(gcf,"myPlot_img.png");
plot1 = Image("myPlot_img.png");
% append the image to chapter
append(ch,plot1);
% append the chapter to report
append(rpt,ch);
I hope this helps!
Categories
Find more on Graphics Object Properties 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!