# How can I choose to show only part of plot/legend?

23 views (last 30 days)
Katarina on 8 May 2014
Answered: Katarina on 8 May 2014
I want to show only one of the "Maxvärde" in the legend.
The code that we used to plot it was:
figure(1);
hold on;
plot(MedelV,'b');
plot(find(Vattenh==(Max)),(Max), 's','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor', 'r');
plot(find(Vattenh==(Min)),(Min), 's','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor', 'y');
plot(Tjugofemperc,'c');
plot(Sjuttiofemperc,'c');
plot(Damnplot,'r');
plot(Sankplot,'r');
plot(x,Vattenh,'k');
lgnd=legend(['Medelvattenstånd ', num2str(Mean, prec),'m'],['Maxvärde ', num2str(Max,prec),'m'],['Maxvärde ', num2str(Max,prec),'m'],['Maxvärde ', num2str(Max,prec),'m'],['Maxvärde ', num2str(Max,prec),'m'],['Minvärde ', num2str(Min,prec),'m'],['25%-percentilen ', num2str(Tjugofem,prec),'m'], ['75%-percentilen ', num2str(Sjuttiofem,prec),'m'],['Dämningsgräns ', num2str(Damn, prec),'m'],['Sänkningsgräns ', num2str(Sank, prec),'m'],'Vattenståndsdata');
rect=[0.63, 0.18, .25, .25];
set(lgnd,'color','none', 'position', rect);
set(gca,'XTick',[0:4:52])
xlabel('Tid i veckor för 2010')
ylabel('Vattenstånd (möh)')
title('Statistiska data för medelvattenståndet i Högsjön under år 2010')
How is this possible??
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Accepted Answer

Niklas Nylén on 8 May 2014
If you start by only plotting one of the max points by adding a second argument to the find function
plot(find(Vattenh==(Max),1),(Max(1)), 's','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor', 'r');
Make the rest of the plot commands and the legend command with only one instance of the "Maxvärde".
Finally, plot the rest of the max values:
plot(find(Vattenh==(Max)),(Max), 's','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor', 'r');
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### More Answers (1)

Katarina on 8 May 2014
Thank you! It worked perfectly!
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Community Treasure Hunt

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

Start Hunting!