imshow inconsistency from version 0.91 to 0.98

Hi all,

I have some broken scripts recently due to the upgrade from 0.91 to 0.98, most of them related to the imshow function.

For example, when I run the following script,

···

from matplotlib.cm import *
from pylab import *

figure(1, (8, 10))
root = axes([0, 0, 1, 1])

xstart, ystart = .03, .97
rows, cols = 30, 2 # to accomodate 58 instances

row_interval, col_interval = .94/rows, .94/cols

cm_keys = [x for x in sorted(datad.keys()) if not x.endswith("_r")]

print len(cm_keys)

X = [0, 1]

Y = array([X, X])

j = 1

for k in cm_keys:
imshow(Y, extent=(xstart, xstart+.7*col_interval,

                  ystart, ystart+.5*row_interval), cmap=get_cmap(name=k))
root.text(xstart+.75*col_interval, ystart, k, size=9)

xstart += col_interval
if j%2==0:

   xstart = .03
   ystart -= row_interval

j += 1

root.set_xlim(0, 1)

root.set_ylim(0, 1)
root.set_axis_off()

savefig(“cm_instances.pdf”)


Different versions gave me different results, with only the old version appears to be correct.

In addition, when I wish to imshow a JPG image through PIL, the newer version gave me very low resolution. Can someone duplicate my observation? I appreciate any solution, thanks.

for k in cm_keys:
    imshow(Y, extent=(xstart, xstart+.7*col_interval,
                      ystart, ystart+.5*row_interval),
cmap=get_cmap(name=k))
    root.text(xstart+.75*col_interval, ystart, k, size=9)
    xstart += col_interval
    if j%2==0:
       xstart = .03
       ystart -= row_interval
    j += 1

root.set_xlim(0, 1)
root.set_ylim(0, 1)
root.set_axis_off()
savefig("cm_instances.pdf")

Different versions gave me different results, with only the old version
appears to be correct.

When I run your script with 91.5 (svn branch) vs 98.3 (svn head), I
see that the text labels do not align with the images (PDF only, not
Agg) in 98.3 and not 91.5. Is this the problem you are describing?

It appears that the image positioning argument is off in the PDF
backend because comparing the trunk vs the head, the labels are in the
same relative position and the images are off. Could one of the PDF
backend gurus look into this?

In addition, when I wish to imshow a JPG image through PIL, the newer
version gave me very low resolution. Can someone duplicate my observation? I
appreciate any solution, thanks.

I am not sure what you are trying here -- can you post a script that
illustrates the problem?

···

On Wed, Sep 24, 2008 at 2:16 PM, Haibao Tang <tanghaibao@...287...> wrote:

John, thanks for the swift reply.

  1. Yes. I later found that whenever I call imshow with extent option more than once, the coordinates will be off.

  2. Here is a sample script

···

from pylab import *

img = imread(“image.png”)
imshow(img)
axis(“off”)
savefig(“image.pdf”)

Just try any png off the web and generate pdf using 0.91 and 0.98. Look closely at the results. There are two major differences. One is that the pixel is larger in 0.98 than in 0.91; also the color looks lossy in 0.98. I suspect that there is more compression for pdf in 0.98, but I am not clear how to reset it.

On Thu, Sep 25, 2008 at 9:37 AM, John Hunter <jdh2358@…287…> wrote:

On Wed, Sep 24, 2008 at 2:16 PM, Haibao Tang <tanghaibao@…287…> wrote:

for k in cm_keys:

imshow(Y, extent=(xstart, xstart+.7*col_interval,
                  ystart, ystart+.5*row_interval),

cmap=get_cmap(name=k))

root.text(xstart+.75*col_interval, ystart, k, size=9)
xstart += col_interval
if j%2==0:
   xstart = .03
   ystart -= row_interval
j += 1

root.set_xlim(0, 1)

root.set_ylim(0, 1)

root.set_axis_off()

savefig(“cm_instances.pdf”)

Different versions gave me different results, with only the old version

appears to be correct.

When I run your script with 91.5 (svn branch) vs 98.3 (svn head), I

see that the text labels do not align with the images (PDF only, not

Agg) in 98.3 and not 91.5. Is this the problem you are describing?

It appears that the image positioning argument is off in the PDF

backend because comparing the trunk vs the head, the labels are in the

same relative position and the images are off. Could one of the PDF

backend gurus look into this?

In addition, when I wish to imshow a JPG image through PIL, the newer

version gave me very low resolution. Can someone duplicate my observation? I

appreciate any solution, thanks.

I am not sure what you are trying here – can you post a script that

illustrates the problem?