Recap of the hierarchy of each plot element: Difference between revisions

From Octave
Jump to navigation Jump to search
No edit summary
No edit summary
Line 33: Line 33:
* figure2 has 2 axes objects inside: a 'y=(sin(x))^2' and a 'y=x^2'
* figure2 has 2 axes objects inside: a 'y=(sin(x))^2' and a 'y=x^2'
* the actual data and data-plot-properties are inside the handles {{Codeline|p}} and {{Codeline|r}}.
* the actual data and data-plot-properties are inside the handles {{Codeline|p}} and {{Codeline|r}}.
To understand how to change things in this situation you ''have to know where you 'are' at this moment''. You 'are' in the second axes object {{Codeline|q}} of the second figure!
So let's say you want to change the line thickness of the data in the first figure:
figure(1)
set(p,'linewidth',3)
You can get the color of the two other plots by referring to their handles:
get(q,'color')
get(r,'color')
Which will give you the RGB code for black (0,0,0) and green (0,1,0).
Have a look at all the things you can change with:
get(q)
And {{Codeline|set} anything that is not to your taste to something else (for what's available see the [http://www.gnu.org/software/octave/doc/interpreter/ manual].
set(p,'marker','*')

Revision as of 14:50, 13 July 2012

First of all, Octave aims at being compatible with Matlab (TM) as much as possible, so the graphics part is very similar too to Matlab. In Octave the first choice to make is the graphics_toolkit(). Standard is the 'gnuplot' toolkit using the Gnuplot software package . The second choice is 'fltk' fltk. You might want to try to test both of them for your plotting aims to see which solves your problem.

After the choice of the graphics_toolkit('gnuplot') or graphics_toolkit('fltk'), there is the following hierarchy to address when make/adapting your plot:

  • root (any hierarchy needs to start somewhere)
  • gcf() (the handle to your figure: one for every figure)
  • gca() (the handle to the axes inside a particular figure (several if you have subplots)
  • p=plot(x,y) (p is the handle (inside the current axes handle) to the data, data symbols, data line thickness, etc)

Let's do an example:

graphics_toolkit('gnuplot');
x=0:0.1:3;
y=sin(x);
p=plot(x,y,'b');

This should get you a plot of a part of a sine wave. Octave has used all standard properties like line widths, fonts, etc, except for the line color which was forced to be blue (via the 'b').

Before going into the hierarchy and how to change things, let's make things more complicated:

graphics_toolkit('gnuplot');
figure(1)
x=0:0.1:3;
y=sin(x);
p=plot(x,y,'b');
figure(2)
subplot(2,1,1);
r=plot(x,y.^2,'og');
subplot(2,1,2);
q=plot(x,x.^2,'k');
  • You now have 2 windows that popped up on your screen: figure1 and figure2.
  • figure2 has 2 axes objects inside: a 'y=(sin(x))^2' and a 'y=x^2'
  • the actual data and data-plot-properties are inside the handles p and r.

To understand how to change things in this situation you have to know where you 'are' at this moment. You 'are' in the second axes object q of the second figure! So let's say you want to change the line thickness of the data in the first figure:

figure(1)
set(p,'linewidth',3)

You can get the color of the two other plots by referring to their handles:

get(q,'color')
get(r,'color')

Which will give you the RGB code for black (0,0,0) and green (0,1,0).

Have a look at all the things you can change with:

get(q)

And {{Codeline|set} anything that is not to your taste to something else (for what's available see the manual.

set(p,'marker','*')