Adding a legend for every new plot in a GUI?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding a legend for every new plot in a GUI?

shank1207
Hello,

In my program I generate a new plot on top of a previous plot everytime i update a slider and push the push button in GUI. I want to add a legend to this new plot based on the value calculated after the slider is updated. Is this possible to update and add new legend everytime i update the slider? 

Like shown in the figure there are three curve the legend has the value of the slider of  the last curve but the color of the first graph. I want to add legend for all three graph

Thank you ,
BR
Reply | Threaded
Open this post in threaded view
|

Re: Adding a legend for every new plot in a GUI?

Andreas Weber-6
Am 16.06.2017 um 10:13 schrieb shank1207:

> Hello,
>
> In my program I generate a new plot on top of a previous plot everytime i
> update a slider and push the push button in GUI. I want to add a legend to
> this new plot based on the value calculated after the slider is updated. Is
> this possible to update and add new legend everytime i update the slider?
> <http://octave.1599824.n4.nabble.com/file/n4683698/filt.png>  
>
> Like shown in the figure there are three curve the legend has the value of
> the slider of  the last curve but the color of the first graph. I want to
> add legend for all three graph

It's always a good idea to create a minimal example which shows what
you've done so far. I can only guess what your code looks like.

If you use "hold on" you can give a legend for every new plot. Try this:

plot (1:10, ";foo;")
hold on
plot (10:20, ";bar;")
plot (30:40, ";baz;")

-- Andy


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Adding a legend for every new plot in a GUI?

shank1207
Hello,

Thanks for your answer, I am sorry for not putting the code anyways it was intuitive of you to guess what I was asking :) ,  the legend works for every new graph but when i tried to modify the code by using num2str for every new graph it doesnt convert the number to string is there a work around for this problem?

Here is what i am doing

 P=num2str(alpha);
semilogx(f,20*log10(abs(H)),";P;",'linewidth',3)

 and this is what i get in the graph
Reply | Threaded
Open this post in threaded view
|

Re: Adding a legend for every new plot in a GUI?

Doug Stewart-4


On Mon, Jun 19, 2017 at 3:22 AM, shank1207 <[hidden email]> wrote:
Hello,

Thanks for your answer, I am sorry for not putting the code anyways it was
intuitive of you to guess what I was asking :) ,  the legend works for every
new graph but when i tried to modify the code by using num2str for every new
graph it doesnt convert the number to string is there a work around for this
problem?

Here is what i am doing

 P=num2str(alpha);
semilogx(f,20*log10(abs(H)),";P;",'linewidth',3)

try

P=";" + num2str(alpha) + ";" ;
semilogx(f,20*log10(abs(H)), P ,'linewidth',3)

or

P=num2str(alpha);
semilogx(f,20*log10(abs(H)),";"+P+";",'linewidth',3)



this is untested by me but give it a try


 and this is what i get in the graph
<http://octave.1599824.n4.nabble.com/file/n4683750/ex2.png>



--
View this message in context: http://octave.1599824.n4.nabble.com/Adding-a-legend-for-every-new-plot-in-a-GUI-tp4683698p4683750.html
Sent from the Octave - General mailing list archive at Nabble.com.

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave



--
DASCertificate for 206392


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Adding a legend for every new plot in a GUI?

shank1207
Hi Doug,

Thank you for your reply , i tested your code but i get something strange.
Reply | Threaded
Open this post in threaded view
|

Re: Adding a legend for every new plot in a GUI?

mmuetzel
try

P = [";" num2str(alpha) ";"] ;
semilogx(f,20*log10(abs(H)), P, 'linewidth',3)

or

P=num2str(alpha);
semilogx(f,20*log10(abs(H)), [";" P ";"], 'linewidth',3)


You should use square brackets to concatenate strings. I think you plotted the sum: double(";") + double(P) + double(";")

Reply | Threaded
Open this post in threaded view
|

Re: Adding a legend for every new plot in a GUI?

Andreas Weber-6
In reply to this post by shank1207
Am 19.06.2017 um 09:22 schrieb shank1207:
>  P=num2str(alpha);
> semilogx(f,20*log10(abs(H)),";P;",'linewidth',3)

this literally sets "P" as legend. You want something like

semilogx(f,20*log10(abs(H)),sprintf(";%.2f;",alpha),'linewidth',3)

or perhaps %i....

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Adding a legend for every new plot in a GUI?

shank1207
Thank you mmuetzel and Andreas Weber-6 both  of your answers works perfectly fine :). Could you just explain me what was I doing wrong and why does your solution work.
Reply | Threaded
Open this post in threaded view
|

Re: Adding a legend for every new plot in a GUI?

mmuetzel
Andreas already explained in his post that you set the string literal "P" as a legend. If you want to use the value of the variable P, don't use quotes around it.