Best way to set scales bounds to appropriate values

Hi, I’m a matplotlib newbie.

An example is worth a thousand words:

In [1]: matplotlib.version

Out[1]: ‘0.99.3’

In [2]: a, b, x = np.zeros(10), np.ones(10), np.arange(10)

In [3]: plot(x, a); plot(x, b)

Well all I see is an empty plot with the two horizontal lines at y=0 and y=1 covered by the upper and lower frame lines.

Why aren’t bounds set a little more larger so the two lines can show properly???

I guess this is a common situation, for example 2 or more stable temperatures: the higher and the lower never show…

How can I fix it?

Thanks for your support.

This will do :

pyplot.xlim(-5,15)

pyplot.ylim(-5,5)

HTH.

Thomas

···

Thomas Lecocq
Geologist
Ph.D.Student (Seismology)
Royal Observatory of Belgium



Date: Wed, 9 Feb 2011 11:53:17 +0100
From: neurino@…287…
To: matplotlib-users@lists.sourceforge.net
Subject: [Matplotlib-users] Best way to set scales bounds to appropriate values

Hi, I’m a matplotlib newbie.

An example is worth a thousand words:

In [1]: matplotlib.version

Out[1]: ‘0.99.3’

In [2]: a, b, x = np.zeros(10), np.ones(10), np.arange(10)

In [3]: plot(x, a); plot(x, b)

Well all I see is an empty plot with the two horizontal lines at y=0 and y=1 covered by the upper and lower frame lines.

Why aren’t bounds set a little more larger so the two lines can show properly???

I guess this is a common situation, for example 2 or more stable temperatures: the higher and the lower never show…

How can I fix it?

Thanks for your support.

------------------------------------------------------------------------------ The ultimate all-in-one performance toolkit: Intel® Parallel Studio XE: Pinpoint memory and threading errors before they happen. Find and fix more than 250 security defects in the development cycle. Locate bottlenecks in serial and parallel code that limit performance. http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Well, not that automatic…

I wonder why matplotlib takes care of settings limits on data but fails in a common situation so I’m forced to override it every time because I don’t know in advance what data I get…

Thanks anyway.

Cheers

neurino

2011/2/9 Thomas Lecocq <thlecocq@…1954…>

···

This will do :

pyplot.xlim(-5,15)

pyplot.ylim(-5,5)

HTH.

Thomas


Thomas Lecocq
Geologist
Ph.D.Student (Seismology)
Royal Observatory of Belgium



Date: Wed, 9 Feb 2011 11:53:17 +0100
From: neurino@…287…
To: matplotlib-users@…1220…sts.sourceforge.net

Subject: [Matplotlib-users] Best way to set scales bounds to appropriate values

Hi, I’m a matplotlib newbie.

An example is worth a thousand words:

In [1]: matplotlib.version

Out[1]: ‘0.99.3’

In [2]: a, b, x = np.zeros(10), np.ones(10), np.arange(10)

In [3]: plot(x, a); plot(x, b)

Well all I see is an empty plot with the two horizontal lines at y=0 and y=1 covered by the upper and lower frame lines.

Why aren’t bounds set a little more larger so the two lines can show properly???

I guess this is a common situation, for example 2 or more stable temperatures: the higher and the lower never show…

How can I fix it?

Thanks for your support.

------------------------------------------------------------------------------ The ultimate all-in-one performance toolkit: Intel® Parallel Studio XE: Pinpoint memory and threading errors before they happen. Find and fix more than 250 security defects in the development cycle. Locate bottlenecks in serial and parallel code that limit performance. http://p.sf.net/sfu/intel-dev2devfeb

_______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Neurino

I’m sure :

1° there must be a parameter in the default behaviour of the subplot to control taht

2° you can always set xlim( min(X)/2, max(X)/2 ) …

Thomas

···

Thomas Lecocq
Geologist
Ph.D.Student (Seismology)
Royal Observatory of Belgium



Date: Wed, 9 Feb 2011 13:47:01 +0100
Subject: Re: [Matplotlib-users] Best way to set scales bounds to appropriate values
From: neurino@…287…
To: thlecocq@…1954…
CC: matplotlib-users@lists.sourceforge.net

Well, not that automatic…

I wonder why matplotlib takes care of settings limits on data but fails in a common situation so I’m forced to override it every time because I don’t know in advance what data I get…

Thanks anyway.

Cheers

neurino

2011/2/9 Thomas Lecocq <thlecocq@…1954…>

This will do :

pyplot.xlim(-5,15)
pyplot.ylim(-5,5)

HTH.

Thomas


Thomas Lecocq
Geologist
Ph.D.Student (Seismology)
Royal Observatory of Belgium



Date: Wed, 9 Feb 2011 11:53:17 +0100
From: neurino@…287…
To: matplotlib-users@lists.sourceforge.net
Subject: [Matplotlib-users] Best way to set scales bounds to appropriate values

Hi, I’m a matplotlib newbie.

An example is worth a thousand words:

In [1]: matplotlib.version

Out[1]: ‘0.99.3’

In [2]: a, b, x = np.zeros(10), np.ones(10), np.arange(10)

In [3]: plot(x, a); plot(x, b)

Well all I see is an empty plot with the two horizontal lines at y=0 and y=1 covered by the upper and lower frame lines.

Why aren’t bounds set a little more larger so the two lines can show properly???

I guess this is a common situation, for example 2 or more stable temperatures: the higher and the lower never show…

How can I fix it?

Thanks for your support.

------------------------------------------------------------------------------ The ultimate all-in-one performance toolkit: Intel® Parallel Studio XE: Pinpoint memory and threading errors before they happen. Find and fix more than 250 security defects in the development cycle. Locate bottlenecks in serial and parallel code that limit performance. http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________ Matplotlib-users mailing list Matplotlib-users@…563…eforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users

I did a little digging and I discovered a function I never noticed before… You can set a “margin” for an axis that can be used for autoscaling purposes.

set_ymargin(self, m) method of matplotlib.axes.AxesSubplot instance
Set padding of Y data limits prior to autoscaling.

*m* times the data interval will be added to each
end of that interval before it is used in autoscaling.


accepts: float in range 0 to 1

So, in your code, if I set ymargin to 0.5, then the limits will automatically be -0.5 to 1.5.

I think this is what you are looking for.

Ben Root

···

On Wed, Feb 9, 2011 at 6:47 AM, neurino <neurino@…287…> wrote:

Well, not that automatic…

I wonder why matplotlib takes care of settings limits on data but fails in a common situation so I’m forced to override it every time because I don’t know in advance what data I get…

Thanks anyway.

Cheers

neurino

Thank you very much, that can help for sure!

Unluckily matplotlib documentation is rather a jungle, just the lack of a methods/properties index for each class makes very hard to find what one’s looking for.

Thanks again.

Greetings

neurino

2011/2/9 Benjamin Root <ben.root@…1304…>

···

On Wed, Feb 9, 2011 at 6:47 AM, neurino <neurino@…287…> wrote:

Well, not that automatic…

I wonder why matplotlib takes care of settings limits on data but fails in a common situation so I’m forced to override it every time because I don’t know in advance what data I get…

Thanks anyway.

Cheers

neurino

I did a little digging and I discovered a function I never noticed before… You can set a “margin” for an axis that can be used for autoscaling purposes.

set_ymargin(self, m) method of matplotlib.axes.AxesSubplot instance
Set padding of Y data limits prior to autoscaling.

*m* times the data interval will be added to each
end of that interval before it is used in autoscaling.




accepts: float in range 0 to 1

So, in your code, if I set ymargin to 0.5, then the limits will automatically be -0.5 to 1.5.

I think this is what you are looking for.

Ben Root