Is it possible to manipulate the line sample the legend shows

1 visualizzazione (ultimi 30 giorni)
I am plotting data, as well as the moving mean of that data and I would like it if the legend would show a sample of the mean over top of the data as seen here: ,rather than showing the data and its mean as separate entries on the legend. I'm not sure that this is possible, and my backup is to just edit it in using GIMP. I appreciate any help, or info that this is infact not doable.
Here's some simple code I've been using to test this out:
test=zeros(100,1);
test1=zeros(100,1);
for i=1:50
test(2*i)=.3;
end
for i=1:50
test1(2*i)=.3;
end
test=test+1;
test1=test1+10;
testmean=movmean(test,20);
test1mean=movmean(test1,20);
figure;
hold on
h1=plot(test1);
h2=plot(test);
h3=plot(test1mean,'r-','LineWidth',2);
h4=plot(testmean,'b-','LineWidth',2);
legend([h3 h4],{'Test1 mean', 'Test mean'})

Risposte (1)

Vashist Hegde
Vashist Hegde il 25 Mar 2021
DISCLAIMER: These are my own views and in no way depict those of MathWorks.
Hi Jesse,
I understand that you want to reflect in your legend.
But the issue is that currently the legend method is designed to accept separate graphic objects and show them separately in the legend. Unfortunately there is no provision to combine two different lines and reflect them as one in the legend.
So the best bet to solve your problem would be to edit it using GIMP.
Hope this helps.

Tag

Prodotti


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by