odd "singular matrix" error

I have no idea what this is. If I create a certain plot first in an application, it throws this error (edited to the key part):

Traceback (most recent call last):

File “thescript.py”, line 2147, in AddPatchBar
ax.add_patch(patch)
File “C:\Python25\lib\site-packages\matplotlib\axes.py”, line 1471, in add_patch
self._update_patch_limits§
File “C:\Python25\lib\site-packages\matplotlib\axes.py”, line 1492, in _update_patch_limits
self.transData.inverted())
File “C:\Python25\lib\site-packages\matplotlib\transforms.py”, line 1954, in inverted
return CompositeGenericTransform(self._b.inverted(), self._a.inverted())
File “C:\Python25\lib\site-packages\matplotlib\transforms.py”, line 1448, in inverted
self._inverted = Affine2D(inv(mtx))
File “C:\Python25\lib\site-packages\numpy\linalg\linalg.py”, line 445, in inv
return wrap(solve(a, identity(a.shape[0], dtype=a.dtype)))
File “C:\Python25\lib\site-packages\numpy\linalg\linalg.py”, line 328, in solve
raise LinAlgError, ‘Singular matrix’
numpy.linalg.linalg.LinAlgError: Singular matrix

But, the odd part is that if I create a completely different and totally separate plot before this one, and then I try to plot this one, I do not get this error and this plot shows fine. That makes no sense to me. Or also, if I plot this “patch” on a plot with a few other lines plotted, it also works.

Does anyone have any idea what could be causing this? Thanks.

What might be happening is that the patch being added has no area. The logic it is failing in is in the autoscaling section, I believe. This is why if there are other things already in the plot or with other patches, then the code works fine because the limits aren’t identical.

Still though, I thought we had enough logic checks to prevent this sort of error. I see you are using Python 2.5, which is older than what we currently support. Which version of matplotlib are you using?

Cheers!
Ben Root

···

On Wed, Dec 31, 2014 at 2:03 AM, C M <cmpython@…1972…> wrote:

I have no idea what this is. If I create a certain plot first in an application, it throws this error (edited to the key part):

Traceback (most recent call last):

File “thescript.py”, line 2147, in AddPatchBar
ax.add_patch(patch)
File “C:\Python25\lib\site-packages\matplotlib\axes.py”, line 1471, in add_patch
self._update_patch_limits(p)
File “C:\Python25\lib\site-packages\matplotlib\axes.py”, line 1492, in _update_patch_limits
self.transData.inverted())
File “C:\Python25\lib\site-packages\matplotlib\transforms.py”, line 1954, in inverted
return CompositeGenericTransform(self._b.inverted(), self._a.inverted())
File “C:\Python25\lib\site-packages\matplotlib\transforms.py”, line 1448, in inverted
self._inverted = Affine2D(inv(mtx))
File “C:\Python25\lib\site-packages\numpy\linalg\linalg.py”, line 445, in inv
return wrap(solve(a, identity(a.shape[0], dtype=a.dtype)))
File “C:\Python25\lib\site-packages\numpy\linalg\linalg.py”, line 328, in solve
raise LinAlgError, ‘Singular matrix’
numpy.linalg.linalg.LinAlgError: Singular matrix

But, the odd part is that if I create a completely different and totally separate plot before this one, and then I try to plot this one, I do not get this error and this plot shows fine. That makes no sense to me. Or also, if I plot this “patch” on a plot with a few other lines plotted, it also works.

Does anyone have any idea what could be causing this? Thanks.


Dive into the World of Parallel Programming! The Go Parallel Website,

sponsored by Intel and developed in partnership with Slashdot Media, is your

hub for all things parallel software development, from weekly thought

leadership blogs to news, videos, case studies, tutorials and more. Take a

look and join the conversation now. http://goparallel.sourceforge.net


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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

What might be happening is that the patch being added has no area. The
logic it is failing in is in the autoscaling section, I believe. This is
why if there are other things already in the plot or with other patches,
then the code works fine because the limits aren't identical.

If it is helpful, when I print the value of the patch, I get this:

patch is: Poly((735597, -12) ...)

What's weird though, is that the other plot I'm talking about is a
*different* plot entirely (different canvas instance), and can be closed
first and still "allow" the patch plot to be shown without errors.

Still though, I thought we had enough logic checks to prevent this sort of
error. I see you are using Python 2.5, which is older than what we
currently support. Which version of matplotlib are you using?

I'm using matplotlib 1.1.0. I could try upgrading.

···

On Wed, Dec 31, 2014 at 9:45 AM, Benjamin Root <ben.root@...1304...> wrote:

Cheers!
Ben Root

On Wed, Dec 31, 2014 at 2:03 AM, C M <cmpython@...287...> wrote:

I have no idea what this is. If I create a certain plot first in an
application, it throws this error (edited to the key part):

Traceback (most recent call last):

  File "thescript.py", line 2147, in AddPatchBar
    ax.add_patch(patch)
  File "C:\Python25\lib\site-packages\matplotlib\axes.py", line 1471, in
add_patch
    self._update_patch_limits(p)
  File "C:\Python25\lib\site-packages\matplotlib\axes.py", line 1492, in
_update_patch_limits
    self.transData.inverted())
  File "C:\Python25\lib\site-packages\matplotlib\transforms.py", line
1954, in inverted
    return CompositeGenericTransform(self._b.inverted(),
self._a.inverted())
  File "C:\Python25\lib\site-packages\matplotlib\transforms.py", line
1448, in inverted
    self._inverted = Affine2D(inv(mtx))
  File "C:\Python25\lib\site-packages\numpy\linalg\linalg.py", line 445,
in inv
    return wrap(solve(a, identity(a.shape[0], dtype=a.dtype)))
  File "C:\Python25\lib\site-packages\numpy\linalg\linalg.py", line 328,
in solve
    raise LinAlgError, 'Singular matrix'
numpy.linalg.linalg.LinAlgError: Singular matrix

But, the odd part is that if I create a completely different and totally
separate plot *before* this one, and *then* I try to plot this one, I do
not get this error and this plot shows fine. That makes no sense to me. Or
also, if I plot this "patch" on a plot with a few other lines plotted, it
also works.

Does anyone have any idea what could be causing this? Thanks.

------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is
your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Still though, I thought we had enough logic checks to prevent this sort of

error. I see you are using Python 2.5, which is older than what we
currently support. Which version of matplotlib are you using?

I'm using matplotlib 1.1.0. I could try upgrading.

Ben and others,

OK, I tried upgrading to Python 2.6 and Matplotlib 1.4.2. The problem with
the singular matrix goes away! But...

...But now I have no patch shown on the plot. This is the function I am
using now to add a patch (editing to just keep the MPL relevant
stuff)...maybe this is no longer a good way?:

    def AddPatch(self,):
                ax = self.subplot
                verts = [
                    (start, y-scaling_value), # left, bottom
                    (start, y+scaling_value), # left, top
                    (stop, y+scaling_value), # right, top
                    (stop, y-scaling_value), # right, bottom
                    (0., 0.), # ignored
                    ]
                codes = [Path.MOVETO,
                         Path.LINETO,
                         Path.LINETO,
                         Path.LINETO,
                         Path.CLOSEPOLY,
                         ]

                x = [start, stop] # x range of box (in data
coordinates)
                height = 12 # of box in device coords (pixels)
                path = mpath.Path([[x[0], -height], [x[1], -height],
                   [x[1], height], [x[0], height],
                   [x[0], -height]])

                #USING THE NEW TRANSFORMS
                fixed_pt_trans = FixedPointOffsetTransform(ax.transData,
(0, y))
                xdata_yfixed =
mtrans.blended_transform_factory(ax.transData, fixed_pt_trans)

                patch = patches.PathPatch(path, transform=xdata_yfixed,
facecolor=color,alpha=0.4, lw=1, edgecolor='grey')

                ax.add_patch(patch)