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 to put a figure plotted by a different function on axes in GUI?

Subject: How to put a figure plotted by a different function on axes in GUI?

From: Borda

Date: 1 Apr, 2013 13:42:15

Message: 1 of 7

Hello!

I've got the following problem. I've made a rather simple GUI with one axes, some input parameters and a button. In the callback event of the button an internal function I wrote creates an nxn subplot on a figure based on the input parameters, of course. What I would like to achieve, is this subplot to be drawn on the axes object instead of a separate figure.
Any idea? Thanks in advance.

Subject: How to put a figure plotted by a different function on axes in

From: dpb

Date: 1 Apr, 2013 14:34:46

Message: 2 of 7

On 4/1/2013 8:42 AM, Borda wrote:
> Hello!
>
> I've got the following problem. I've made a rather simple GUI with one
> axes, some input parameters and a button. In the callback event of the
> button an internal function I wrote creates an nxn subplot on a figure
> based on the input parameters, of course. What I would like to achieve,
> is this subplot to be drawn on the axes object instead of a separate
> figure.
> Any idea? Thanks in advance.

Create the figure/axes in initialization saving handle(s) on creation
where they're accessible (either GLOBAL or as user data in appropriate
place). Then use the forms of plot(), subplot() and friends w/ that handle.

--

Subject: How to put a figure plotted by a different function on axes in

From: Borda

Date: 1 Apr, 2013 21:09:14

Message: 3 of 7

It seems I wasn't clear: the problem is that the actual plotting takes place in the function, the figure is created by this function on a separate window - so the subplot() command is within - and what I want is the final figure to be displayed/copied on the axes without returning the data used for plotting to the main function, where the axes is.

dpb <none@non.net> wrote in message <kjc5u4$hp9$1@speranza.aioe.org>...
> On 4/1/2013 8:42 AM, Borda wrote:
> > Hello!
> >
> > I've got the following problem. I've made a rather simple GUI with one
> > axes, some input parameters and a button. In the callback event of the
> > button an internal function I wrote creates an nxn subplot on a figure
> > based on the input parameters, of course. What I would like to achieve,
> > is this subplot to be drawn on the axes object instead of a separate
> > figure.
> > Any idea? Thanks in advance.
>
> Create the figure/axes in initialization saving handle(s) on creation
> where they're accessible (either GLOBAL or as user data in appropriate
> place). Then use the forms of plot(), subplot() and friends w/ that handle.
>
> --

Subject: How to put a figure plotted by a different function on axes in

From: dpb

Date: 1 Apr, 2013 22:40:19

Message: 4 of 7

On 4/1/2013 4:09 PM, Borda wrote:
...[please don't toppost--hard conversation follow makes]...
> dpb <none@non.net> wrote in message <kjc5u4$hp9$1@speranza.aioe.org>...
>> On 4/1/2013 8:42 AM, Borda wrote:
>> > Hello!
>> >
>> > I've got the following problem. I've made a rather simple GUI with one
>> > axes, some input parameters and a button. In the callback event of the
>> > button an internal function I wrote creates an nxn subplot on a figure
>> > based on the input parameters, of course. What I would like to achieve,
>> > is this subplot to be drawn on the axes object instead of a separate
>> > figure.
>> > Any idea? Thanks in advance.
>>
>> Create the figure/axes in initialization saving handle(s) on creation
>> where they're accessible (either GLOBAL or as user data in appropriate
>> place). Then use the forms of plot(), subplot() and friends w/ that
>> handle.

> It seems I wasn't clear: the problem is that the actual plotting takes
> place in the function, the figure is created by this function on a
> separate window - so the subplot() command is within - and what I want
> is the final figure to be displayed/copied on the axes without returning
> the data used for plotting to the main function, where the axes is.

I can't figure out what you're trying to describe, sorry. Try some
pseudo-code that illustrates the issue, maybe? Or hope somebody else is
better at getting the idea...

--

Subject: How to put a figure plotted by a different function on axes in

From: Borda

Date: 3 Apr, 2013 16:06:16

Message: 5 of 7

button_callback
 reading_inputs
 plotting_function(reading_inputs)
 %display the output on handles.axes1
guidata(hObject, handles)


function out = plotting_function(inputs)
 out = [];
 subplot() % opens up a new figure
 plot(inputs) % plots on the figure
 subplot()
 plot()
 .
 .
 .
end


So if I press the button on the GUI, the inputs are read and the plotting function runs. The subplot function automatically opens up a new figure and the actual plot is on this figure (which is on a separate window). What I want is the content of this window to be copied or displayed on the axes1, if its possible without modifying the plotting_function.
A checked the subplot function itself, it looks for me that it gets the CurrentFigure and plots on that. Is it possible to set the Current figure to be the axes1?

Subject: How to put a figure plotted by a different function on axes in

From: dpb

Date: 3 Apr, 2013 17:27:41

Message: 6 of 7

On 4/3/2013 11:06 AM, Borda wrote:
> button_callback
> reading_inputs
> plotting_function(reading_inputs)
> %display the output on handles.axes1
> guidata(hObject, handles)
>
>
> function out = plotting_function(inputs)
> out = [];
> subplot() % opens up a new figure
> plot(inputs) % plots on the figure
> subplot()
> plot()
> .
> .
> .
> end
>
>
> So if I press the button on the GUI, the inputs are read and the
> plotting function runs. The subplot function automatically opens up a
> new figure and the actual plot is on this figure (which is on a separate
> window). What I want is the content of this window to be copied or
> displayed on the axes1, if its possible without modifying the
> plotting_function.
> A checked the subplot function itself, it looks for me that it gets the
> CurrentFigure and plots on that. Is it possible to set the Current
> figure to be the axes1?

What is axes1 and where did it come from?

You can use an existing subplot w/ the subplot(m,n,p) functional form or
(altho I've not ever tried it when H is not a subplot; doesn't say you
can't) make a given axes the current axes w/ the subplot(H) form.

doc subplot
doc plot

for details.

--

Subject: How to put a figure plotted by a different function on axes in

From: Borda

Date: 6 Apr, 2013 16:00:14

Message: 7 of 7

> What is axes1 and where did it come from?
>
> You can use an existing subplot w/ the subplot(m,n,p) functional form or
> (altho I've not ever tried it when H is not a subplot; doesn't say you
> can't) make a given axes the current axes w/ the subplot(H) form.
>
> doc subplot
> doc plot
>
> for details.
>

I've tried it and it works! Thanks!

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