help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tight yaxis for a given x-range


From: James Sherman Jr.
Subject: Re: tight yaxis for a given x-range
Date: Fri, 6 Nov 2015 12:32:08 -0500

On Fri, Nov 6, 2015 at 3:19 AM, OT <address@hidden> wrote:
> Hi;
> I plot data, everything is fine; then I want to rescale the plot on a small
> x-axis (line 2 below).
> I would like to restrict the y-axis, tightly to the data in the x-range.
> From previous posts, I guess
> this is possible (see link below), but I did not manage to do it.
>
> plot(1:100,cos((1:100)/10));         %%%% just plotting
> axis([27,38]);                                %%%% restricting the x-axis;
> it works, but the y-axis is way too large
> axis("tight",[27,38]);                      %%%% trying to make the y-axis
> tight; not ok
> ylim("auto");                                  %%%% trying again; not ok
> ylim("tight");                                  %%%% trying again; not ok
>
> Any help appreciated, have a great day :-)
>
> (the following thread is very related but too old for posting:
> http://octave.1599824.n4.nabble.com/axis-tight-only-for-specific-axes-td2330430.html
> )
>
> ===================
> octave:10> version
> ans = 3.8.1
> octave:11> graphics_toolkit
> ans = gnuplot
>
> uname -a
>  3.13.0-62-generic #102-Ubuntu SMP Tue Aug 11 14:29:36 UTC 2015 x86_64
> x86_64 x86_64 GNU/Linux
>
>
>
>
> --
> View this message in context: 
> http://octave.1599824.n4.nabble.com/tight-yaxis-for-a-given-x-range-tp4673300.html
> Sent from the Octave - General mailing list archive at Nabble.com.
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/help-octave

I don't see any option within ylim to support what you want (Its
certainly not there in the help  text).  In fact, I'm kinda surprised
that ylim didn't return an error/warning about an unrecognized option.

I'm sure there is a better way to do this (I'm not very experienced at
all with gui handles and the like), but I've attached a very quick and
dirty hack (not really tested at all except in the specific case
you've described), but I think it will do what you want.  The only
input is an optional axis handle.  It finds all points in the data set
that have x-values within the current limits of the x-axis.  Then
finds the max and min values of their y-values, and sets those to be
the y limits.

Hope this helps.

James Sherman Jr.

Attachment: ylim_tight.m
Description: Binary data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]