Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How can I plot multiple graphs on the same single plot using GUI?

Subject: How can I plot multiple graphs on the same single plot using GUI?

From: Bernard Lee

Date: 17 Nov, 2008 14:32:01

Message: 1 of 11

I have three radio buttons, each plots a single graph.
for eg. 1st radio button -> a V graph
          2nd radio button -> a D graph
          3rd radio button -> a S graph
How can I plot multiple graphs on the same single plot using GUI?
for eg. if i select the 1st and 3rd radio button, i will get the V and S graphs on the
          same plot
          if i select the 2nd and 3rd radio button, i will get the D and S graphs on the
          same plot.

Can you help me with ideas to create such radiobuttons as well as display using plot command. thanks alot.

Subject: How can I plot multiple graphs on the same single plot using GUI?

From: Johan Carlson

Date: 17 Nov, 2008 14:50:19

Message: 2 of 11

"Bernard Lee" <leeshijun@gmail.com> wrote in message <gfrv91$cep$1@fred.mathworks.com>...
> I have three radio buttons, each plots a single graph.
> for eg. 1st radio button -> a V graph
> 2nd radio button -> a D graph
> 3rd radio button -> a S graph
> How can I plot multiple graphs on the same single plot using GUI?
> for eg. if i select the 1st and 3rd radio button, i will get the V and S graphs on the
> same plot
> if i select the 2nd and 3rd radio button, i will get the D and S graphs on the
> same plot.
>
> Can you help me with ideas to create such radiobuttons as well as display using plot command. thanks alot.

Hi,

What you need to do is to get a handle to the axes of your plot. For example, when you create the first plot (or the axes) you can set the 'Tag' property, by writing

set(gca,'Tag','myplotaxes');

Then, in the callback of your radio buttons, do something like:

axes(findobj('Tag','myplotaxes'));
hold on;
plot(....)

If I understand your problem correctly, something like this should do the trick...

/JC

Subject: How can I plot multiple graphs on the same single plot using

From: Venky

Date: 17 Nov, 2008 14:52:59

Message: 3 of 11

<as well as display using plot command. thanks alot.>

you can use Hold On and Hold Off commands in addition with Plot(), to plot the graphs in the same window

Subject: How can I plot multiple graphs on the same single plot using GUI?

From: Bernard Lee

Date: 17 Nov, 2008 15:26:02

Message: 4 of 11

"Johan Carlson" <Johan.E.Carlson@gmail.com> wrote in message <gfs0bb$quv$1@fred.mathworks.com>...
> "Bernard Lee" <leeshijun@gmail.com> wrote in message <gfrv91$cep$1@fred.mathworks.com>...
> > I have three radio buttons, each plots a single graph.
> > for eg. 1st radio button -> a V graph
> > 2nd radio button -> a D graph
> > 3rd radio button -> a S graph
> > How can I plot multiple graphs on the same single plot using GUI?
> > for eg. if i select the 1st and 3rd radio button, i will get the V and S graphs on the
> > same plot
> > if i select the 2nd and 3rd radio button, i will get the D and S graphs on the
> > same plot.
> >
> > Can you help me with ideas to create such radiobuttons as well as display using plot command. thanks alot.
>
> Hi,
>
> What you need to do is to get a handle to the axes of your plot. For example, when you create the first plot (or the axes) you can set the 'Tag' property, by writing
>
> set(gca,'Tag','myplotaxes');
>
> Then, in the callback of your radio buttons, do something like:
>
> axes(findobj('Tag','myplotaxes'));
> hold on;
> plot(....)
>
> If I understand your problem correctly, something like this should do the trick...
>
> /JC

Hi JC,

thanks alot. Sorry I forgot to mention that I have actually 8 radio buttons, meaning 8 graphs in all. does what you say earlier still applies? I wrote 3 radio buttons because I wanted to simplify the problem..

Subject: How can I plot multiple graphs on the same single plot using GUI?

From: Paul Mennen

Date: 18 Nov, 2008 02:18:04

Message: 5 of 11

> thanks alot. Sorry I forgot to mention that I have actually 8 radio buttons,
> meaning 8 graphs in all. does what you say earlier still applies?

Another solution you may want to try is to use "plt" (available on the
file exchange) instead of "plot" which was designed especially for the
situation when many traces are needed. It doesn't use radio buttons are
you are suggesting, but it uses almost the same idea by using the trace ID
labels as a sort of radio button. You simply click on the trace ID label to
toggle a trace on or off. (The trace ID changes in an obvious way so you
know if it is on or off.)

I would first try "plt5.m", in the demo folder - the simplest example of
how to use plt. Note that 5 traces are plotted on a single graph and you
can easily use the mouse to select which traces are on or off. plt also has
all the capabilities of plotyy, plotyyy, ect. Extensive documentation on plt
is available in the plt.chm help file.

~Paul

Subject: How can I plot multiple graphs on the same single plot using GUI?

From: Bernard Lee

Date: 18 Nov, 2008 12:09:02

Message: 6 of 11

"Johan Carlson" <Johan.E.Carlson@gmail.com> wrote in message <gfs0bb$quv$1@fred.mathworks.com>...
> "Bernard Lee" <leeshijun@gmail.com> wrote in message <gfrv91$cep$1@fred.mathworks.com>...
> > I have three radio buttons, each plots a single graph.
> > for eg. 1st radio button -> a V graph
> > 2nd radio button -> a D graph
> > 3rd radio button -> a S graph
> > How can I plot multiple graphs on the same single plot using GUI?
> > for eg. if i select the 1st and 3rd radio button, i will get the V and S graphs on the
> > same plot
> > if i select the 2nd and 3rd radio button, i will get the D and S graphs on the
> > same plot.
> >
> > Can you help me with ideas to create such radiobuttons as well as display using plot command. thanks alot.
>
> Hi,
>
> What you need to do is to get a handle to the axes of your plot. For example, when you create the first plot (or the axes) you can set the 'Tag' property, by writing
>
> set(gca,'Tag','myplotaxes');
>
> Then, in the callback of your radio buttons, do something like:
>
> axes(findobj('Tag','myplotaxes'));
> hold on;
> plot(....)
>
> If I understand your problem correctly, something like this should do the trick...
>
> /JC

Hi JC,

Your method solved my problem...but now i dont know how to update the legend of the graph.

Subject: How can I plot multiple graphs on the same single plot using GUI?

From: Johan Carlson

Date: 18 Nov, 2008 14:22:01

Message: 7 of 11

"Bernard Lee" <leeshijun@gmail.com> wrote in message <gfub8t$b2r$1@fred.mathworks.com>...
> "Johan Carlson" <Johan.E.Carlson@gmail.com> wrote in message <gfs0bb$quv$1@fred.mathworks.com>...
> > "Bernard Lee" <leeshijun@gmail.com> wrote in message <gfrv91$cep$1@fred.mathworks.com>...
> > > I have three radio buttons, each plots a single graph.
> > > for eg. 1st radio button -> a V graph
> > > 2nd radio button -> a D graph
> > > 3rd radio button -> a S graph
> > > How can I plot multiple graphs on the same single plot using GUI?
> > > for eg. if i select the 1st and 3rd radio button, i will get the V and S graphs on the
> > > same plot
> > > if i select the 2nd and 3rd radio button, i will get the D and S graphs on the
> > > same plot.
> > >
> > > Can you help me with ideas to create such radiobuttons as well as display using plot command. thanks alot.
> >
> > Hi,
> >
> > What you need to do is to get a handle to the axes of your plot. For example, when you create the first plot (or the axes) you can set the 'Tag' property, by writing
> >
> > set(gca,'Tag','myplotaxes');
> >
> > Then, in the callback of your radio buttons, do something like:
> >
> > axes(findobj('Tag','myplotaxes'));
> > hold on;
> > plot(....)
> >
> > If I understand your problem correctly, something like this should do the trick...
> >
> > /JC
>
> Hi JC,
>
> Your method solved my problem...but now i dont know how to update the legend of the graph.


I guess you could use a similar trick, i.e. keeping track of the legend object by doing something like:

h = legend(....)
set(h,'tag','mylegend');

Then each time you update the plot you can check if the legend exists, by
 if ~isempty(findobj('tag','mylegend'),
  delete(findobj('tag','mylegend');
  ... and then draw a new legend in the same way as above.
end

Haven't tried it, but something like this should do it.

/JC

Subject: How can I plot multiple graphs on the same single plot using GUI?

From: Bernard Lee

Date: 18 Nov, 2008 16:19:02

Message: 8 of 11

"Johan Carlson" <Johan.E.Carlson@gmail.com> wrote in message <gfs0bb$quv$1@fred.mathworks.com>...
> "Bernard Lee" <leeshijun@gmail.com> wrote in message <gfrv91$cep$1@fred.mathworks.com>...
> > I have three radio buttons, each plots a single graph.
> > for eg. 1st radio button -> a V graph
> > 2nd radio button -> a D graph
> > 3rd radio button -> a S graph
> > How can I plot multiple graphs on the same single plot using GUI?
> > for eg. if i select the 1st and 3rd radio button, i will get the V and S graphs on the
> > same plot
> > if i select the 2nd and 3rd radio button, i will get the D and S graphs on the
> > same plot.
> >
> > Can you help me with ideas to create such radiobuttons as well as display using plot command. thanks alot.
>
> Hi,
>
> What you need to do is to get a handle to the axes of your plot. For example, when you create the first plot (or the axes) you can set the 'Tag' property, by writing
>
> set(gca,'Tag','myplotaxes');
>
> Then, in the callback of your radio buttons, do something like:
>
> axes(findobj('Tag','myplotaxes'));
> hold on;
> plot(....)
>
> If I understand your problem correctly, something like this should do the trick...
>
> /JC

Hi JC,

Your method solved my problem...but now i dont know how to update the legend of the graph.

Subject: How can I plot multiple graphs on the same single plot using GUI?

From: Adam

Date: 18 Nov, 2008 18:00:20

Message: 9 of 11

"Bernard Lee" <leeshijun@gmail.com> wrote

> Your method solved my problem...but now i dont know how to update the legend of the graph.

What do you want to update? Just the names?

legendString = {'one', 'two'};

hL = legend(legendString);

Now if you modify legendString you can update the legend

legendString{1} = 'three';
set(hL, 'String', legendString)

Sorry if this doesn't answer your question (I didn't read everything because I would approach the problem differently)

~Adam

Subject: How can I plot multiple graphs on the same single plot using GUI?

From: Johan Carlson

Date: 18 Nov, 2008 18:43:02

Message: 10 of 11

"Adam" <not.real@email.com> wrote in message <gfuvrk$4l4$1@fred.mathworks.com>...
> "Bernard Lee" <leeshijun@gmail.com> wrote
>
> > Your method solved my problem...but now i dont know how to update the legend of the graph.
>
> What do you want to update? Just the names?
>
> legendString = {'one', 'two'};
>
> hL = legend(legendString);
>
> Now if you modify legendString you can update the legend
>
> legendString{1} = 'three';
> set(hL, 'String', legendString)
>
> Sorry if this doesn't answer your question (I didn't read everything because I would approach the problem differently)
>
> ~Adam



I accidentally posted a reply higher up in this thread... Didn't know that was possible. Anyway, I answered the legend question there as well.

Sorry about double postings...

/JC

Subject: How can I plot multiple graphs on the same single plot using GUI?

From: Bernard Lee

Date: 20 Nov, 2008 08:57:02

Message: 11 of 11

"Johan Carlson" <Johan.E.Carlson@gmail.com> wrote in message <gfv2bm$58o$1@fred.mathworks.com>...
> "Adam" <not.real@email.com> wrote in message <gfuvrk$4l4$1@fred.mathworks.com>...
> > "Bernard Lee" <leeshijun@gmail.com> wrote
> >
> > > Your method solved my problem...but now i dont know how to update the legend of the graph.
> >
> > What do you want to update? Just the names?
> >
> > legendString = {'one', 'two'};
> >
> > hL = legend(legendString);
> >
> > Now if you modify legendString you can update the legend
> >
> > legendString{1} = 'three';
> > set(hL, 'String', legendString)
> >
> > Sorry if this doesn't answer your question (I didn't read everything because I would approach the problem differently)
> >
> > ~Adam
>
>
>
> I accidentally posted a reply higher up in this thread... Didn't know that was possible. Anyway, I answered the legend question there as well.
>
> Sorry about double postings...
>
> /JC

Thanks alot to all who helped...my program is working..appreciate it!!!

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us