Search code examples
octave

centering the y axis arrow


I am currently trying to draw an oscillation using Octave. This is what I want to achieve in the end:

oscillation curve with the y axis arrow in the middle1

In this diagram, the y axis arrow is drawn in the middle of the graph instead of at the top or bottom.

I think this way it makes a lot of sense because the arrow kind of mirrors the graph itself periodically.

Now, what I have so far:

x = [0:.1:10];
plot(x, sin(x);
box off

Which looks like this: graph of sin(0:.1:10) with box off

But I can't get the y axis arrow to be in the middle. So far I've read

But I can't find anything about positioning the axis. Thanks for any help in advance.


Solution

  • Using your example:

    x = [0:.1:10];
    plot(x, sin(x));
    box off
    set( gca, 'xaxislocation', 'origin' )
    

    Some more, possibly helpful tips:

    In general, if you don't know what parameters are available in a graphical object handle, and you want to "check", you can use get with an empty string, e.g. get( gca, '' ) to check all the parameters that you can 'get' or 'set' on the current axes object.

    Similarly, if you want to check what values a particular parameter can be set to, you can do, e.g. set( gca, 'xaxislocation' ), i.e. without providing the value to set it to. If that particular parameter only accepts values from a specific set of values (instead of e.g. a numerical array), then Octave will then show you what these options are (and also which is the default).

    Obviously, if you know what you're looking for, you can also just go straight to the relevant page in the octave manual and search the page for it :)

    Since the online manual is quite large, and has no 'search' facility of its own (it does within octave, but the online version doesn't), in order to jump straight to the relevant section I often find it useful to do a duckduckgo (or google) site-specific search, e.g. "xaxislocation site:https://octave.org/doc/v6.2.0/"