Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MATLAB Legend Groups

I'm using MATLAB to plot some data. I would like to create the legend so that it divides information into two types, say Type1 and Type2. Each type of data has several specific lines of data which i am plotting. Suppose that:

  • Type1 data has line1 and line2
  • Type2 data has line1 and line2 and line3

This would make a 5 line plot. Now for the legend i can do something like:

legend('Type1: line1','Type1: line2','Type2: line1', ...
       'Type2: line2','Type2: line3');

But that repeats the 'Types' and the best way would be something that would look like:

(final legend output)

  • Type1:
    • line1
    • line2
  • Type2:
    • line1
    • line2
    • line3

Thanks a lot. Hope you can help with my first question here :D

like image 384
Vetras Avatar asked Jul 12 '11 14:07

Vetras


People also ask

Can you have multiple legends in MATLAB?

The function LEGEND allows creation of only one legend object per axes. Multiple legends can be created by using the function COPYOBJ to make a copy of a legend object.

What does legend do in MATLAB?

legend creates a legend with descriptive labels for each plotted data series. For the labels, the legend uses the text from the DisplayName properties of the data series. If the DisplayName property is empty, then the legend uses a label of the form 'dataN' .

How do I manually add a legend in MATLAB?

x = linspace(0,10); y1 = sin(x); y2 = sin(0.9*x); y3 = sin(0.8*x); y4 = sin(0.7*x); y5 = sin(0.6*x); y6 = sin(0.5*x); plot(x,y1,'DisplayName','sin(x)') hold on plot(x,y2,'DisplayName','sin(0.9x)') plot(x,y3,'DisplayName','sin(0.8x)') plot(x,y4,'DisplayName','sin(0.7x)') plot(x,y5,'DisplayName','sin(0.6x)') plot(x,y6,' ...


1 Answers

You may want to have a look at LEGENDFLEX that you can download from the Matlab File Exchange

like image 118
Jonas Avatar answered Oct 18 '22 03:10

Jonas