bug on plot

Matplotlib 0.54.1 still has trouble plotting column or row

    > vectors:

Try replacing matplotlib.lines.set_data with the following and let me
know if it passes all your tests. You will need to add ravel to the
list of functions imported from numerix at the top of the lines
module.

    def set_data(self, x, y):
        try: del self._xc, self._yc
        except AttributeError: pass

        self._x = asarray(x, Float)
        self._y = asarray(y, Float)

        if len(self._x.shape)>1: self._x = ravel(self._x)
        if len(self._y.shape)>1: self._y = ravel(self._y)

        if len(self._y)==1 and len(self._x)>1:
            self._y = self._y*ones(self._x.shape, Float)

        if self._useDataClipping: self._xsorted = self._is_sorted(self._x)

Thanks!
JDH

Thanks John,

with your patch, it is now possible to plot vectors with shape(n,1)(column vector). However, vectors of shape (1,n)(row vector) give the following error:

>>> from matplotlib.matlab import *
>>> a=arange(10)
>>> a.shape=(1,10)
>>> plot(a)
[<matplotlib.lines.Line2D instance at 0x40af5a8c>]
>>> show()
Traceback (most recent call last):
  File "/usr/lib/python2.3/site-packages/matplotlib/backends/backend_gtkagg.py", line 75, in callback
    self.draw()
  File "/usr/lib/python2.3/site-packages/matplotlib/backends/backend_gtkagg.py", line 42, in draw
    agg.draw()
  File "/usr/lib/python2.3/site-packages/matplotlib/backends/backend_agg.py", line 296, in draw
    self.figure.draw(self.renderer)
  File "/usr/lib/python2.3/site-packages/matplotlib/figure.py", line 130, in draw
    for a in self.axes: a.draw(renderer)
  File "/usr/lib/python2.3/site-packages/matplotlib/axes.py", line 614, in draw
    line.draw(renderer)
  File "/usr/lib/python2.3/site-packages/matplotlib/lines.py", line 191, in draw
    xt, yt = self._transform.numerix_x_y(x, y)
ValueError: x and y must be equal length sequences
_

Matplotlib 0.54.1 still has trouble plotting column or row
vectors:
Try replacing matplotlib.lines.set_data with the following and let me
know if it passes all your tests. You will need to add ravel to the
list of functions imported from numerix at the top of the lines
module.
def set_data(self, x, y):
try: del self._xc, self._yc
except AttributeError: pass
self._x = asarray(x, Float)
self._y = asarray(y, Float)
if len(self._x.shape)>1: self._x = ravel(self._x)
if len(self._y.shape)>1: self._y = ravel(self._y)
if len(self._y)==1 and len(self._x)>1:
self._y = self._y*ones(self._x.shape, Float)
if self._useDataClipping: self._xsorted = self._is_sorted(self.x)
Thanks!
JDH


fiocruz4.jpg
Flávio Codeço Coelho, PhD

Programa de Computação Científica

Fundação Oswaldo Cruz

Rio de Janeiro – Brasil

···

On Fri, 2004-05-28 at 17:32, John Hunter wrote: