[matplotlib-devel] bug in imshow for PDF, EPS output

2009-08-05 Thread Michael Fitzgerald


Hi all,

I've come across an apparent bug in imshow when outputting to PDF and  
EPS files.  (I haven't tested other vector formats.)  It manifests as  
a small scaling error between the raster image and the axes coordinates.


I have attached a test script to illustrate the problem.  The  
(correct) PNG output file shows a green 'X' at the common point  
between four pixels near the center of the raster image.  The extent  
is chosen such that the coordinates refer to pixel centers.  The PDF  
and EPS output files show a misalignment between the X and the pixel  
boundaries -- zoom in to see it clearly.  Also, the topmost row and  
rightmost column appear truncated.


I am using svn r7395.

Thanks for the attention,
Mike

import numpy as n
import matplotlib as mpl
import pylab

ny, nx = 50, 50
im = n.arange(ny*nx) % 3
im.shape = (ny, nx)

extent = (-0.5, nx-0.5, -0.5, ny-0.5)

fig = pylab.figure(0, figsize=(5,5))
fig.clear()
fig.hold(True)
ax = fig.add_subplot(111)

ax.imshow(im, extent=extent,
  interpolation='nearest',
  cmap=mpl.cm.gray,
  origin='lower')
ax.set_autoscale_on(False)
ax.plot(((nx-1)/2.,), ((ny-1)/2.,), 'x', c='g', ms=4, mew=1.25)

pylab.draw()
#pylab.show()
dpi = 300
pylab.savefig('test.png', dpi=dpi)
pylab.savefig('test.pdf', dpi=dpi)
pylab.savefig('test.eps', dpi=dpi)
--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


[matplotlib-devel] LineCollection and alpha

2008-03-12 Thread Michael Fitzgerald
Hi all,
I found a small bug in LineCollection, which gives an exception when setting
alpha.  This is manifested in e.g. hlines and vlines:

In [1]: hlines((0,),(-1,),(1,),color='b',alpha=0.1)
---
IndexErrorTraceback (most recent call last)

XXX/ipython console in module()

XXX/lib/python/matplotlib/pyplot.py in hlines(*args, **kwargs)
   1700 hold(h)
   1701 try:
- 1702 ret =  gca().hlines(*args, **kwargs)
   1703 draw_if_interactive()
   1704 except:

XXX/lib/python/matplotlib/axes.py in hlines(self, y, xmin, xmax, colors,
linestyles, label, **kwargs)
   2609 linestyles=linestyles,
label=label)
   2610 self.add_collection(coll)
- 2611 coll.update(kwargs)
   2612
   2613 minx = min(xmin.min(), xmax.min())

XXX/lib/python/matplotlib/artist.py in update(self, props)
438 if func is None or not callable(func):
439 raise AttributeError('Unknown property %s'%k)
-- 440 func(v)
441 changed = True
442 self.eventson = store

XXX/lib/python/matplotlib/collections.py in set_alpha(self, alpha)
306 else:
307 artist.Artist.set_alpha(self, alpha)
-- 308 self._facecolors[:, 3] = alpha
309 self._edgecolors[:, 3] = alpha
310

IndexError: invalid index



This appears to be because LineCollection.__init__() only uses
Collection._edgecolors, and sets _facecolors to an empty array.  I don't
know if it's the proper solution, but I did this to get it to work:

Index: lib/matplotlib/collections.py
===
--- lib/matplotlib/collections.py   (revision 5000)
+++ lib/matplotlib/collections.py   (working copy)
@@ -305,7 +305,8 @@
 except TypeError: raise TypeError('alpha must be a float')
 else:
 artist.Artist.set_alpha(self, alpha)
-self._facecolors[:, 3] = alpha
+if len(self._facecolors):
+self._facecolors[:, 3] = alpha
 self._edgecolors[:, 3] = alpha

 def get_linewidths(self):


Best,
Mike
-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


[matplotlib-devel] Arrow bugfix

2008-03-10 Thread Michael Fitzgerald


Hi all,

I encountered problems with the Arrow patch, which broke sometime  
recently.  I'm attaching a fix (diff against svn r4999).


Best,
Mike



arrow_patch.diff
Description: Binary data
-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


[matplotlib-devel] small bugfix

2007-04-11 Thread Michael Fitzgerald

Hi all,

I found a small bug, where Figure.clf() was erroneously leaving some axes 
instances in the Figure.axes list.  It turns out the method was deleting 
items from the list while iterating over it.  Attached is a patch.

Mike

Index: figure.py
===
--- figure.py	(revision 3198)
+++ figure.py	(working copy)
@@ -1,7 +1,7 @@
 
 Figure class -- add docstring here!
 
-import sys
+import sys, copy
 import artist
 from artist import Artist
 from axes import Axes, Subplot, PolarSubplot, PolarAxes
@@ -515,7 +515,7 @@
 
 Clear the figure
 
-for ax in self.axes:
+for ax in copy.copy(self.axes):
 ax.cla()
 self.delaxes(ax)
 
-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


[matplotlib-devel] PS, dpi, and imshow

2006-08-31 Thread Michael Fitzgerald

Hi all,

I have a question about the PS backend (building on the thread  
imshow with PS backend from ~ a month ago).  Evidently this backend  
is fixed at 72 dpi.  This isn't a problem with vector information.   
However, it would seem that one would want to use a higher resolution  
when plotting figures that use imshow() for raster data, since this  
command has several choices for interpolation.  As I understand, the  
AxesImage is sampled at this low-resolution when being written to PS/ 
EPS.  Subsequent interpolation is done when printing, or viewing with  
ghostview.  For the (originally?) raster data, gv seems to use a  
nearest-neighbor scheme, making the image blocky.  It would be nice  
to use matplotlib's interpolation instead.  Is there a fundamental  
reason this needs to be fixed at 72 dpi?  As some publishers ask for  
EPS files of e.g. 300 dpi, I would think it's theoretically possible  
to export at different resolutions.  My understanding is that the  
_preview_ image in the file is supposed to be 72 dpi.

One possible workaround is to scale up the size of the figure (in  
inches), but then fonts, line thickness, marker sizes, etc. must also  
be scaled, making it less-than-satisfactory.

Thank you in advance for any enlightenment, and please forgive my  
ignorance -- I must admit I don't know that much about PS, nor about  
the specific scheme used in matplotlib for getting the image data  
into the postscript file, so I may be critically mistaken in the  
above assessment.

Best,
Mike

(P.S. please cc me, as I'm not subscribed)





-
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642
___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel