Caption - Legend

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Caption - Legend

yamane
Hello,

Maybe this is a stupid question, but I didn't found an answer in https://octave.sourceforge.io/octave/function/legend.html

I have 2 arrays:

X_axis = 1 line x 11 columns;
Y_axis = 7 lines x 11 columns;

I generate a graph with:

figure(1);
loglog(X_axis,abs(Y_axis));
grid minor;
legend show

But the legend show me:
data1
data2
data3
data4
data5
data6
data7

How may I change the caption of each data? :-)

Many thanks,
Renato


Reply | Threaded
Open this post in threaded view
|

Re: Caption - Legend

mmuetzel
Am 16. April 2020 um 17:48 Uhr schrieb "Renato S. Yamane":

> Hello,
>
> Maybe this is a stupid question, but I didn't found an answer in https://octave.sourceforge.io/octave/function/legend.html
>
> I have 2 arrays:
> X_axis = 1 line x 11 columns;
> Y_axis = 7 lines x 11 columns;
>
> I generate a graph with:
>
> figure(1);
> loglog(X_axis,abs(Y_axis));
> grid minor;
> legend show
>
> But the legend show me:
> data1
> data2
> data3
> data4
> data5
> data6
> data7
>
> How may I change the caption of each data? :-)

Does the demo help?:
>> demo legend 1
legend example 1:
 clf;
 plot (rand (2));
 title ("legend called with string inputs for labels");
 h = legend ("foo", "bar");
 legend (h, "location", "northeastoutside");
 set (h, "fontsize", 20);


Markus



Reply | Threaded
Open this post in threaded view
|

Re: Caption - Legend

BGreen
In reply to this post by yamane

On Thu, Apr 16, 2020 at 11:49 AM Renato S. Yamane <[hidden email]> wrote:
Hello,

Maybe this is a stupid question, but I didn't found an answer in https://octave.sourceforge.io/octave/function/legend.html

I have 2 arrays:

X_axis = 1 line x 11 columns;
Y_axis = 7 lines x 11 columns;

I generate a graph with:

figure(1);
loglog(X_axis,abs(Y_axis));
grid minor;
legend show

But the legend show me:
data1
data2
data3
data4
data5
data6
data7

How may I change the caption of each data? :-)

Many thanks,
Renato


Try something like this:

plot(rand(3))

legtxt{1,1} = "abcd";
legtxt{2,1} = "wxyz";
legtxt{3,1} = "Line 3";
legend(legtxt);

See the documentation here for much more you can do to customize the legend.


Reply | Threaded
Open this post in threaded view
|

Re: Caption - Legend

yamane
Em qui., 16 de abr. de 2020 às 17:27, Brett Green <[hidden email]> escreveu:

On Thu, Apr 16, 2020 at 11:49 AM Renato S. Yamane <[hidden email]> wrote:
Hello,

Maybe this is a stupid question, but I didn't found an answer in https://octave.sourceforge.io/octave/function/legend.html

I have 2 arrays:

X_axis = 1 line x 11 columns;
Y_axis = 7 lines x 11 columns;

I generate a graph with:

figure(1);
loglog(X_axis,abs(Y_axis));
grid minor;
legend show

But the legend show me:
data1
data2
data3
data4
data5
data6
data7

How may I change the caption of each data? :-)


Try something like this:

plot(rand(3))

legtxt{1,1} = "abcd";
legtxt{2,1} = "wxyz";
legtxt{3,1} = "Line 3";
legend(legtxt);


 Thanks Brett,

I forgot to tell that the amount of graphs is not fixed.
The amount of graphs is a variable in the code.

There is an way to "legtxt" (in your example) keep increasing until reach the number of graphs?

Example, if I have 10 graphs, the legtxt should be from {1,1} til {10,1}

Many thanks,
Renato 


Reply | Threaded
Open this post in threaded view
|

Re: Caption - Legend

BGreen
Certainly - just use a for loop.

nplots = 10;

plot(rand(nplots))
for j=1:nplots
legtxt{j,1} = strcat("This is plot #",num2str(j));
end
legend(legtxt);

nplots would be replaced with the variable in your code. Alternatively,

clear all

nplots = 3;

namelist = {"a";"b";"c";"d";"e"}

plot(rand(nplots))
for j=1:nplots
legtxt{j,1} = namelist{j,1};
end
legend(legtxt);

has a long user-defined list of names, and then takes only as many as needed for the legend.

On Mon, Apr 20, 2020 at 10:45 AM Renato S. Yamane <[hidden email]> wrote:

 Thanks Brett,

I forgot to tell that the amount of graphs is not fixed.
The amount of graphs is a variable in the code.

There is an way to "legtxt" (in your example) keep increasing until reach the number of graphs?

Example, if I have 10 graphs, the legtxt should be from {1,1} til {10,1}

Many thanks,
Renato