[Matplotlib-users] python crash when loading pylab

2009-10-26 Thread Andrey Naumov
When i run my script, python crashes on string:

*from pylab import *
*


While tracing the error i've found that the problem is in _path.pyd
Here is the problem string in file transforms.py:
from matplotlib._path import affine_transform

I've checked if _path.pyd is missing some libs and i saw that msvcp90.dll
and msvcr90.dll are missing.
But copying them tp mpl folder didn't help ;(

I'm using WinXP SP3, VS2008, Python 2.6.3, NumPy 1.3.0, SciPy 0.7.1,
MatPlotLib matplotlib-0.99.1
Also i'm attaching windows log on this error






























  ठਠ--
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Malaren lake by Matplotlib Basemap

2009-10-26 Thread Jeff Whitaker
kkondo wrote:
> Dear Jeff
>
> Thank you for your reply.
>
> I have found that the "resolution='f'" in basemap crashes when drawing
> the Japanese Isles. Is it another flaw in GSHHS?
>

Kentaro: I cannot reproduce this crash. What version of the GEOS library
do you have? I am using 3.1.1.

-Jeff

P.S. cc'ing the matplotlib mailing list.
> % python japanese_isles.py
> GEOS_ERROR: TopologyException: side location conflict
> (130.468,32.5594,32.5594)
> Bus error
> % cat japanese_isles.py
> from mpl_toolkits.basemap import Basemap
> import matplotlib.pyplot as plt
> m = Basemap(llcrnrlon=121.,llcrnrlat=23.,urcrnrlon=152.,urcrnrlat=48.,
> resolution='f',projection='tmerc',lon_0=135.,lat_0=35.)
> m.drawcoastlines()
> plt.show()
> $ python
> Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53)
> [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import numpy
> >>> numpy.__version__
> '1.3.0'
> >>> import mpl_toolkits.basemap
> >>> mpl_toolkits.basemap.__version__
> '0.99.4'
>
> P.S. "resolution='f'" works fine for the British Isles:
> m = Basemap(llcrnrlon=-10.5,llcrnrlat=49.5,urcrnrlon=3.5,urcrnrlat=59.5,
> resolution='f',projection='tmerc',lon_0=-4.36,lat_0=54.7)
>
> Sincerely,
> Kentaro Kondo
>
>
> On 2009/10/25, at 22:40, Jeff Whitaker wrote:
>
>> kkondo wrote:
>>> Hello
>>>
>>> I want to get the shoreline of Malaren lake as
>>> http://en.wikipedia.org/wiki/File:La3-demis-malaren.png. But I find
>>> that the following Matplotlib-Basemap program does not draw its
>>> shoreline but its islands. Is it the flaw of GSHHS?
>>>
>>>
>>> from mpl_toolkits.basemap import Basemap
>>> import matplotlib.pyplot as plt
>>> m = Basemap(width=18,height=9,
>>> resolution='f',projection='tmerc',lon_0=17.5,lat_0=59.5)
>>> plt.clf()
>>> m.drawcoastlines()
>>> m.fillcontinents(color='coral',lake_color='aqua')
>>> m.drawmapboundary(fill_color='aqua')
>>> m.drawrivers(color='b')
>>> plt.show()
>>>
>>>
>>> Sincerely,
>>> Kentaro Kondo
>>>
>>>
>> Kentaro: Apparently it's a flaw in GSHHS. I tried the online line map
>> creator at http://www.aquarius.geomar.de/cgi-bin/map-cgi.pl (which
>> uses GMT, which is the source of GSSHS) and got the same thing. It's
>> possible that it's fixed in the latest version of GSHHS (1.10) - I'll
>> take a look and let you know.
>>
>> -Jeff
>
> ---
> 富士通(株)
> 次世代IT・ITSプロジェクト室
> インフラ協調プロジェクト
> 近藤 kko...@jp.fujitsu.com
> (044)754-8513 fax (044)754-3292
> 〒211-8588 神奈川県川崎市中原区上小田中4-1-1
>


--
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Malaren lake by Matplotlib Basemap

2009-10-26 Thread Jeff Whitaker
Jeff Whitaker wrote:
> kkondo wrote:
>   
>> Hello
>>
>> I want to get the shoreline of Malaren lake as 
>> http://en.wikipedia.org/wiki/File:La3-demis-malaren.png. But I find 
>> that the following Matplotlib-Basemap program does not draw its 
>> shoreline but its islands. Is it the flaw of GSHHS?
>>
>>
>> from mpl_toolkits.basemap import Basemap
>> import matplotlib.pyplot as plt
>> m = Basemap(width=18,height=9,
>> resolution='f',projection='tmerc',lon_0=17.5,lat_0=59.5)
>> plt.clf()
>> m.drawcoastlines()
>> m.fillcontinents(color='coral',lake_color='aqua')
>> m.drawmapboundary(fill_color='aqua')
>> m.drawrivers(color='b')
>> plt.show()
>>
>>
>> Sincerely,
>> Kentaro Kondo
>>
>>
>> 
> Kentaro: Apparently it's a flaw in GSHHS.  I tried the online line map 
> creator at http://www.aquarius.geomar.de/cgi-bin/map-cgi.pl (which uses 
> GMT, which is the source of GSSHS) and got the same thing.  It's 
> possible that it's fixed in the latest version of GSHHS (1.10) - I'll 
> take a look and let you know.
>
> -Jeff
>   

Kentaro:  The problem still exists in GSHHS 1.10.  I don't know what to 
suggest other than using a shapefile to plot the lakes in that region, 
if you can find one.

-Jeff

--
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Can't import pylab on Windows with C API

2009-10-26 Thread Michael Droettboom
I'm not aware of anyone trying this, but I suspect it's related to 
differences in how DLL paths are searched on Windows vs. shared objects 
on Linux.

This sort of seems like a lower-level Python issue -- I wonder if you 
could find other projects that do this and see where matplotlib 
differs.  For instance, can you import numpy this way?  If not, I would 
bring this up on the Python users list and see if they have any advice.

Mike

Nick Hilton wrote:
> Hello all,
>
> I am trying to plot things from C using pylab.  The configuration:
>
> Window XP 32 bits
> Python-2.6.3
> numpy-1.3.0
> matplotlib-0.99.1.
>
> I can easily do this on Linux, but the same code does not work on Windows.  
> Here is a test program that tries to import pylab:
>
> #include 
>
> #include 
>
>
>
> int main(void)
>
> {
>
> PyObject * module = NULL;
>
>
>
> Py_Initialize();
>
>
>
> module = PyImport_ImportModule("matplotlib.pylab");
>
>
>
> if(module == NULL || module == Py_None)
>
> {
>
> printf("no\n");
>
> PyErr_Print();
>
> PyErr_Clear();
>
> }
>
> else
>
> {
>
> printf("yes\n");
>
> }
>
>
>
> Py_Finalize();
>
>
>
> return 0;
>
> }
>
> The code above works fine with Python2.6 and Linux.  However, on Windows it 
> fails; here is the output:
>
> no
>
> Traceback (most recent call last):
>
>   File "C:\Python26\lib\site-packages\matplotlib\pylab.py", line 206, in 
> 
>
> from matplotlib import mpl  # pulls in most modules
>
>   File "C:\Python26\lib\site-packages\matplotlib\mpl.py", line 1, in 
>
> from matplotlib import artist
>
>   File "C:\Python26\lib\site-packages\matplotlib\artist.py", line 5, in 
> 
>
> from transforms import Bbox, IdentityTransform, TransformedBbox, 
> TransformedPath
>
>   File "C:\Python26\lib\site-packages\matplotlib\transforms.py", line 34, in 
> 
>
> from matplotlib._path import affine_transform
>
> ImportError: DLL load failed: The specified module could not be found.
>
> Has anybody tried this?
>
> Thanks!
> Nick
>
>
>
>   
>
> --
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay 
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> ___
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>   

-- 
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA


--
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Movable Legend

2009-10-26 Thread Andrea Gavana
Hi All,

a while ago, Che posted a nice example on how to drag a legend
with the mouse. I have upgraded to matplotlib 0.99.1 and it looks like
the nice example is not working anymore: for the life of me I can't
figure out what's wrong. I attach the runnable sample submitted
originally.

Any suggestion regarding what's wrong with the code?

Thank you in advance.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/
http://thedoomedcity.blogspot.com/
#Boa:Frame:Frame1

import wx

import matplotlib
matplotlib.interactive(True)
matplotlib.use('WXAgg')
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
from matplotlib.figure import Figure

def create(parent):
return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1NOTEBOOK1, wxID_FRAME1PANEL1, 
] = [wx.NewId() for _init_ctrls in range(3)]

class PlotPanel(wx.Panel):
def __init__(self, parent,id = -1, color = None,\
dpi = None, style = wx.NO_FULL_REPAINT_ON_RESIZE, **kwargs):
self.gotLegend = 0  #to begin, legend is not picked.

self.parent = parent
self.line_collections_list = []

wx.Panel.__init__(self, parent, **kwargs)

self.figure = Figure(None, dpi)
self.canvas = FigureCanvasWxAgg( self, -1, self.figure )

#Connect all the mpl events
self.canvas.mpl_connect('motion_notify_event', self.on_motion)
self.canvas.mpl_connect('pick_event', self.on_pick)
self.canvas.mpl_connect('button_release_event', self.on_release)

self._SetInitialSize()

self.Bind(wx.EVT_SIZE, self._onSize)

self.draw()

#a few sizing issues, not relevant to this draggable legend point.
def _onSize(self, event):
self._SetSize()
event.Skip()

def _SetSize( self ):
pixels = tuple( self.GetClientSize() )
self.SetSize( pixels )
self.canvas.SetSize( pixels )
self.figure.set_size_inches( float( pixels[0] )/self.figure.get_dpi(),
 float( pixels[1] )/self.figure.get_dpi() )

def _SetInitialSize(self,):
pixels = self.parent.GetClientSize()
self.canvas.SetSize(pixels)
self.figure.set_size_inches( (pixels[0])/self.figure.get_dpi(), 
 (pixels[1])/self.figure.get_dpi(), forward=True )

def draw(self): 
self.subplot = self.figure.add_subplot(111)
line, = self.subplot.plot([1],[6],'o',picker=5) 
if self.gotLegend == 0:  #need to prevent it from keep appending each 
time if it is just moving legend.
self.line_collections_list.append(line)

#Legend.
self.legend = self.subplot.legend(self.line_collections_list, ['1'], 
numpoints=1)
self.legend.set_picker(self.my_legend_picker)

#pick up the legend patch
def my_legend_picker(self, legend, event): 
return self.legend.legendPatch.contains(event)   

#pick the legend
def on_pick(self, event):
legend = self.legend
if event.artist == legend:
bbox = self.legend.get_window_extent()  #gets the box of the legend.
self.mouse_x = event.mouseevent.x  #get mouse coordinates at time 
of pick.
self.mouse_y = event.mouseevent.y
print 'mouse x position at pick time', self.mouse_x
print 'mouse y position at pick time', self.mouse_y
self.legend_x = bbox.xmin  #get legend coordinates at time 
of pick.
self.legend_y = bbox.ymin 
print 'Legend x position @ pick time = ', self.legend_x
print 'Legend y position @ pick time= ', self.legend_y
self.gotLegend = 1  #indicates we picked up the legend.

#drag the legend
def on_motion(self, event):  
if self.gotLegend == 1:
x = mouse_diff_x = self.mouse_x - event.x  #how much the mouse 
moved.
y = mouse_diff_y = self.mouse_y - event.y

print 'motion_event.x =', event.x
print 'motion_event.y =', event.y
print 'mouse moved x = ', mouse_diff_x
print 'mouse moved y = ', mouse_diff_y

#move the legend from its previous location by that same amount
loc_in_canvas = self.legend_x - mouse_diff_x, self.legend_y - 
mouse_diff_y
#transform into legend coordinate system
loc_in_norm_axes = 
self.legend.parent.transAxes.inverted().transform_point(loc_in_canvas)
self.legend._loc = tuple(loc_in_norm_axes)

self.canvas.draw()

#release the legend
def on_release(self, event):
if self.gotLegend == 1:
self.gotLegend = 0
print 'legend released'

class Frame1(wx.Frame):
def _init_coll_boxSizer1_Items(self, parent):
# generated method, don't edit

parent.AddWindow(self.notebook1, 1,

Re: [Matplotlib-users] Py2.5.4 on Win7

2009-10-26 Thread Stan West
> From: Werner F. Bruhin [mailto:werner.bru...@free.fr] 
> Sent: Saturday, October 24, 2009 06:23
> 
> Installed Py 2.6.3 and I don't see the issue there, but not 
> all libraries I use are on 2.6 yet.
> 
> So, I thought lets install Python(x, y) and give this a try, 
> but I can't find a Python 2.5.x version of it - is this still 
> available?

Apparently: From the download page for python(x,y)
(http://www.pythonxy.com/download.php), in the "Site" column, the "Mirror 1"
link (http://ftp.ntua.gr/pub/devel/pythonxy/) took me to four releases of
python(x,y), of which two contain Python 2.5.something.


--
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Py2.5.4 on Win7

2009-10-26 Thread Stan West
> From: Werner F. Bruhin [mailto:werner.bru...@free.fr] 
> Sent: Saturday, October 24, 2009 09:03
> 
> I got it working by adding "C:\Python25" to the path 
> environment variable.  Works but smells very much like a work around.

I'm glad you got things working.  For what it's worth, my path contains not
only C:\Python25 but also C:\Python25\Scripts and several other
subdirectories; I don't recall adding them to the path myself, so I suspect
that python(x,y) did so during installation.


--
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Movable Legend

2009-10-26 Thread Jae-Joon Lee
This is a known bug. While this is fixed in the svn, this did go into
the maint. branch.
As a workaround, add the following line after line 70.

self.legend.set_axes(self.subplot)

Regards,

-JJ


On Mon, Oct 26, 2009 at 9:44 AM, Andrea Gavana  wrote:
> Hi All,
>
>    a while ago, Che posted a nice example on how to drag a legend
> with the mouse. I have upgraded to matplotlib 0.99.1 and it looks like
> the nice example is not working anymore: for the life of me I can't
> figure out what's wrong. I attach the runnable sample submitted
> originally.
>
> Any suggestion regarding what's wrong with the code?
>
> Thank you in advance.
>
> Andrea.
>
> "Imagination Is The Only Weapon In The War Against Reality."
> http://xoomer.alice.it/infinity77/
> http://thedoomedcity.blogspot.com/
>
> --
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> ___
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>

--
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Adding-custom-axes-within-a-subplot redux

2009-10-26 Thread Jae-Joon Lee
On Sun, Oct 25, 2009 at 7:30 PM, George Nurser  wrote:
> it seems a pity that
> fig.add_axes can't accept the transform directly.

While this is certainly possible, but it is a bit tricky to get it
correct due to the underlying design of the matplotlib. On the other
hand, I think it solves some problems, but not all. And the
axes_locator attribute in the current matplotlib is an attempt for a
more general solution.
For example, what you want can be achieved with something like below.

from mpl_toolkits.axes_grid.inset_locator import InsetPosition
ax= subplot(111)
ax2=axes([0, 0, 0, 0]) # The initial value is ignored in this example
ax2.set_axes_locator(InsetPosition(ax, [0.2, 0.2, 0.4, 0.4]))

Regards,

-JJ

--
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] SVG output: possible bug

2009-10-26 Thread Craig Lang
Greetings,

I am using matplotlib to generate an SVG plot containing a mixture of
Annotations and Circles. I noticed that the annotation text does not appear
at exactly the correct location when outputting to SVG. The difference is
minor, but definitely present.

The following will reproduce the problem in the form of two files, an svg
and a png:

--
from matplotlib.pyplot import figure
from matplotlib.text import Annotation
from matplotlib.patches import Circle
from matplotlib.transforms import IdentityTransform

f = figure(1)
a = f.add_subplot(111)
text = Annotation('H', (0.4, 0.4), va='center', ha='center',
size='xx-large', transform=IdentityTransform())
a.add_artist(text)
a.grid(True)
f.savefig("incorrect.svg")
f.savefig("correct.png")
--
IdentityTransform() is used to workaround a bug in add_artist() (see
http://www.nabble.com/Annotation-add_artist-bug-tt19052971.html )

Further investigation reveals that this problem occurs with ps and pdf
output as well. It seems that all backend_*.py files in
/usr/share/pyshared/matplotlib/backends suffer from this problem. I have
poked around in a few files but can't see any obvious fixes.

Has anyone encountered this problem before and found a decent workaround?

Thanks,
Craig
--
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] sharing the x-axis with another plot's y-axis

2009-10-26 Thread Ernest Adrogué
Hi,
I know about sharing an axis with another subplot, but
is it possible to share the x-axis with another subplot's
y-axis (or the other way around)?

Thanks.
Ernest

--
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] drawing arrows

2009-10-26 Thread per freem
hi all,

i am trying to plot a series of arrows between points on a scatter
plot, using the following code:

import matplotlib.pyplot as plt
from matplotlib.patches import FancyArrowPatch
from numpy import *
from scipy import *

def plot_arrows(init_val, all_vals, c='k'):
plt.figure()
ax = plt.gca()
prev_val = init_val
for x, y in all_vals[1:]:
ax = plt.gca()
start_coord = prev_val
plt.scatter(start_coord[0], start_coord[1], c=c)
end_coord = (x, y)
ax.add_patch(FancyArrowPatch(start_coord, end_coord,
 arrowstyle='->', edgecolor=c,
facecolor=c, mutation_scale=10))
prev_val = end_coord
plt.scatter(all_vals[-1][0], all_vals[-1][1], c=c)

points = rand(5,2)
init = [0, 0]
plot_arrows(init, points)
plt.show()

this usually works, but sometimes when i give it a set of points (not
necessarily ones generated randomly), then it gives me the error:

Library/Python/2.5/site-packages/matplotlib/bezier.pyc in
split_path_inout(path, inside, tolerence, reorder_inout)
265
266 if bezier_path is None:
--> 267 raise ValueError("The path does not seem to intersect
with the patch")
268
269 bp = zip(bezier_path[::2], bezier_path[1::2])

ValueError: The path does not seem to intersect with the patch

any idea what could be causing this? it seems like any arbitrary set
of points should work here, since you can always draw an arrow between
any two points not sure what is the root of this error. any help
would be really appreciated. thank you.

--
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] SVG output: possible bug

2009-10-26 Thread Stan West
From: Craig Lang [mailto:cr...@grapheneindustries.com] 
Sent: Monday, October 26, 2009 13:04

Greetings,

I am using matplotlib to generate an SVG plot containing a mixture of
Annotations and Circles. I noticed that the annotation text does not appear at
exactly the correct location when outputting to SVG. The difference is minor,
but definitely present.

The following will reproduce the problem in the form of two files, an svg and
a png:

[...]

Further investigation reveals that this problem occurs with ps and pdf output
as well. It seems that all backend_*.py files in
/usr/share/pyshared/matplotlib/backends suffer from this problem. I have poked
around in a few files but can't see any obvious fixes. 

Has anyone encountered this problem before and found a decent workaround? 

Thanks,
Craig

(I'm cc'ing the development list.)

I believe I have some understanding of what's happening. The backends you
mentioned use routines in ft2font.cpp to align text. The algorithms for
aligning text use information returned by the function compute_string_bbox,
which bases the bounding box on the extent of the painted regions of the
glyphs. The width and height of that box are computed by get_width_height
(also in ft2font.cpp) and returned to the renderer, which hands them off to
the _get_layout method of each text object. That method leaves the anchor
point (near the lower-left corner of the text) undisturbed for left-aligned
text, but for centered or right-aligned text shifts it left by half or all,
respectively, of the bounding box width. The resulting coordinate is returned
to the text object's draw method, which eventually calls the renderer.

The difference arises in how the renderers for the different backends treat
the anchor coordinate. The bitmap Agg backend uses draw_glyphs_to_bitmap in
ft2font.cpp, and I think that that function aligns the leftmost ink of the
bitmapped text to the anchor point. Because the anchor point was adjusted, if
at all, by the width of the inked area, it's the inked area of the text that
is left-, center-, or right-aligned. In contrast, the SVG, PS, and PDF
backends make text objects at that anchor coordinate in their output. (I'm
glossing over more complex cases like that of text converted to paths).
However, the inked area of the first character may be to the right (as with
your H) or to the left (as often with lowercase j) of the anchor point. (See,
for example, http://www.tortall.net/mu/wiki/CairoTutorial#understanding-text.)
If the text is to be center- or right-aligned, the anchor point has been
adjusted only for the width of the inked area, so any offset of the ink
relative to the initial anchor is simply translated to the other alignments.
Thus, your H was too far to the right.

I showed some different manifestations of this behavior in a tracker I filed
last year, at http://sourceforge.net/tracker/?func=detail
 &atid=560721&aid=1978234&group_id=80706. The digits and decimal points
of the y-axis tick labels are out of alignment, the x-axis tick labels have
different baselines, and the numbers in the middle are not aligned in columns
(although in PDF and SVG saves of the figure, the left-aligned numbers do lie
in columns).

I'd like to see matplotlib have at least the option of aligning using the
advance widths of the characters in the horizontal direction and the font-wide
ascent and descent (rather than the ascent and descent of the particular
glyphs in each text object) in the vertical direction. Is it important to have
the option of aligning to the glyph ink, too (and to do it consistently across
backends)? As time permits, I'm willing to contribute coding effort.

Craig, I don't know of a work-around at the moment, but I'll write again if I
think of one.

--
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] drawing arrows

2009-10-26 Thread Jae-Joon Lee
The only case I can think of now is that the two points are too close
(with in a few points). This could happen during the "shrink", or
during the "mutate"
(http://matplotlib.sourceforge.net/users/annotations_guide.html#annotating-with-arrow).
But it would be great if you can pinpoint this down and post a script
that reproduce the problem.

Regards,

-JJ


On Mon, Oct 26, 2009 at 1:57 PM, per freem  wrote:
> hi all,
>
> i am trying to plot a series of arrows between points on a scatter
> plot, using the following code:
>
> import matplotlib.pyplot as plt
> from matplotlib.patches import FancyArrowPatch
> from numpy import *
> from scipy import *
>
> def plot_arrows(init_val, all_vals, c='k'):
>    plt.figure()
>    ax = plt.gca()
>    prev_val = init_val
>    for x, y in all_vals[1:]:
>        ax = plt.gca()
>        start_coord = prev_val
>        plt.scatter(start_coord[0], start_coord[1], c=c)
>        end_coord = (x, y)
>        ax.add_patch(FancyArrowPatch(start_coord, end_coord,
>                                     arrowstyle='->', edgecolor=c,
> facecolor=c, mutation_scale=10))
>        prev_val = end_coord
>    plt.scatter(all_vals[-1][0], all_vals[-1][1], c=c)
>
> points = rand(5,2)
> init = [0, 0]
> plot_arrows(init, points)
> plt.show()
>
> this usually works, but sometimes when i give it a set of points (not
> necessarily ones generated randomly), then it gives me the error:
>
> Library/Python/2.5/site-packages/matplotlib/bezier.pyc in
> split_path_inout(path, inside, tolerence, reorder_inout)
>    265
>    266     if bezier_path is None:
> --> 267         raise ValueError("The path does not seem to intersect
> with the patch")
>    268
>    269     bp = zip(bezier_path[::2], bezier_path[1::2])
>
> ValueError: The path does not seem to intersect with the patch
>
> any idea what could be causing this? it seems like any arbitrary set
> of points should work here, since you can always draw an arrow between
> any two points not sure what is the root of this error. any help
> would be really appreciated. thank you.
>
> --
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> ___
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>

--
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users