Problem setting clim for subplots

Dear all

I am puzzled: in the following code, when I call clim() after having created 3 subplots, only the last subplot takes the new limits into account. All other subplots ignore it. Xlim(), on the countrary, works as intended. Everything works fine when I set the clim() at creation time.

Am I doing something wrong, or is this a bug, please ? Any help much appreciated !
The offending code is below. I use python 2.7.5 andmatplotlib-1.3.x-py2.7-macosx-10.8-intel.egg

Thanks for any help!

BEGIN_SOURCE_

import matplotlib.pyplot as plt
import numpy as np

x = np.asarray([[1, 100, 20], [50, 1, 20], [20, 10, 5]])

Problem when setting clim after having created the two subplots:

only the last subplot honors the request

1. Create the pcolormeshes in subplots

h = plt.figure()
for i in range(131, 134):
plt.subplot(i)
plt.pcolormesh(x)
plt.colorbar()
print(h.number)

2. Now set the clim()

plt.figure(h.number)
for i in range(131, 134):
plt.subplot(i)
plt.clim((5,10))
plt.xlim((2,3))

plt.savefig(‘after_creation.png’)
plt.show()

No problem when setting clim while creating each subplot

h = plt.figure()
for i in range(131, 134):
plt.subplot(i)
plt.pcolormesh(x)
plt.colorbar()
plt.clim((5,10))
plt.xlim((2,3))

plt.savefig(‘while_creating.png’)
plt.show()

END_SOURCE_

Dear all

I am puzzled: in the following code, when I call clim() *after* having
created 3 subplots, only the last subplot takes the new limits into
account. All other subplots ignore it. Xlim(), on the countrary, works
as intended. Everything works fine when I set the clim() at creation time.

Am I doing something wrong, or is this a bug, please ? Any help much
appreciated !

It's a bug. Would you report it as an issue on github, please? (You could wait 24 hours; if I come up with a PR for fix before then there will be no need for the issue report.)

Eric

···

On 2013/06/06 2:08 AM, Julien Cornebise wrote:

The offending code is below. I use python 2.7.5
andmatplotlib-1.3.x-py2.7-macosx-10.8-intel.egg

Thanks for any help!

__BEGIN_SOURCE___

import matplotlib.pyplot as plt
import numpy as np

x = np.asarray([[1, 100, 20], [50, 1, 20], [20, 10, 5]])

# Problem when setting clim *after* having created the two subplots:
# only the last subplot honors the request

# 1. Create the pcolormeshes in subplots
h = plt.figure()
for i in range(131, 134):
     plt.subplot(i)
     plt.pcolormesh(x)
     plt.colorbar()
print(h.number)

# 2. Now set the clim()
plt.figure(h.number)
for i in range(131, 134):
     plt.subplot(i)
     plt.clim((5,10))
     plt.xlim((2,3))

plt.savefig('after_creation.png')
plt.show()

# No problem when setting clim *while* creating each subplot
h = plt.figure()
for i in range(131, 134):
     plt.subplot(i)
     plt.pcolormesh(x)
     plt.colorbar()
     plt.clim((5,10))
     plt.xlim((2,3))

plt.savefig('while_creating.png')
plt.show()

__END_SOURCE___

------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. A cloud service to automate IT design, transition and operations
2. Dashboards that offer high-level views of enterprise services
3. A single system of record for all IT processes
http://p.sf.net/sfu/servicenow-d2d-j

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

I see what the problem is, so I expect to come up with a PR for it in a day or two.

In the meantime, as a workaround, change your clim() line to:

     plt.gca()._gci().set_clim((5,10))

Eric

···

On 2013/06/06 2:08 AM, Julien Cornebise wrote:

Dear all

I am puzzled: in the following code, when I call clim() *after* having
created 3 subplots, only the last subplot takes the new limits into
account. All other subplots ignore it. Xlim(), on the countrary, works
as intended. Everything works fine when I set the clim() at creation time.

Thans a lot Eric for the fast and detailed answer!

···

On Thu, Jun 6, 2013 at 9:24 PM, Eric Firing <efiring@…202…> wrote:

On 2013/06/06 2:08 AM, Julien Cornebise wrote:

Dear all

I am puzzled: in the following code, when I call clim() after having

created 3 subplots, only the last subplot takes the new limits into

account. All other subplots ignore it. Xlim(), on the countrary, works

as intended. Everything works fine when I set the clim() at creation time.

I see what the problem is, so I expect to come up with a PR for it in a

day or two.

In the meantime, as a workaround, change your clim() line to:

 plt.gca()._gci().set_clim((5,10))

Eric


How ServiceNow helps IT people transform IT departments:

  1. A cloud service to automate IT design, transition and operations

  2. Dashboards that offer high-level views of enterprise services

  3. A single system of record for all IT processes

http://p.sf.net/sfu/servicenow-d2d-j


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Julien,

See https://github.com/matplotlib/matplotlib/pull/2119 for a proposed fix.

Eric