Tony S Yu wrote:
> 
> On Sep 26, 2008, at 5:01 PM, Eric Firing wrote:
>> Also, if an image cannot be resolved by the output device, info is 
>> lost--one might not see anything at a location where there actually is 
>> a value--whereas with markers, a marker will always show up, and the 
>> only problem is that one can't necessarily distinguish a single point 
>> from a cluster.
>>
>> The real problem with all-zero values is that plot can't handle 
>> "plot([],[])".  One can work around this by putting in bogus values to 
>> plot a single point, saving the line, and then setting the line data 
>> to empty; or, better, by not using the high-level plot command, but by 
>> generating the Line2D object and adding it to the axes.  The Line2D 
>> initializer is happy with empty x and y sequences. I think if you use 
>> this approach it will kill two bugs (failure on all-zeros with sparse 
>> and full arrays) with one very simple stone.
>>
>> Eric
> 
> 
> Thanks for the tip Eric. Below is a patch for spy that implements Eric's 
> suggestion. This patch seems to work for a couple simple tests on my 
> end: sparse and dense arrays with non-zero and all-zero values.

Tony,

Thanks.  I will take care of this shortly, along with fixing the failure 
of plot([],[]) and maybe a few other things.

Eric

> 
> A couple of notes:
> 
> * the call to `add_artist` isn't needed to show the correct plot, but it 
> may be helpful for debugging.
> 
> * the docstring for `spy` suggests that a Line2D instance is returned, 
> but `spy` currently returns a list with a Line2D instance. I set 
> all-zero arrays to return a list also, for consistency.
> 
> 
> -Tony
> 
> 
> 
> Index: matplotlib/lib/matplotlib/axes.py
> ===================================================================
> --- matplotlib/lib/matplotlib/axes.py    (revision 6123)
> +++ matplotlib/lib/matplotlib/axes.py    (working copy)
> @@ -6723,9 +6723,9 @@
>          else:
>              if hasattr(Z, 'tocoo'):
>                  c = Z.tocoo()
> -                y = c.row
> -                x = c.col
> -                z = c.data
> +                nonzero = c.data != 0.
> +                y = c.row[nonzero]
> +                x = c.col[nonzero]
>              else:
>                  Z = np.asarray(Z)
>                  if precision is None: mask = Z!=0.
> @@ -6733,8 +6733,12 @@
>                  y,x,z = mlab.get_xyz_where(mask, mask)
>              if marker is None: marker = 's'
>              if markersize is None: markersize = 10
> -            lines = self.plot(x, y, linestyle='None',
> -                         marker=marker, markersize=markersize, **kwargs)
> +            if len(x) == 0:
> +                lines = [mlines.Line2D([], [])]
> +                self.add_artist(lines[0])
> +            else:
> +                lines = self.plot(x, y, linestyle='None',
> +                             marker=marker, markersize=markersize, 
> **kwargs)
>              nr, nc = Z.shape
>              self.set_xlim(xmin=-0.5, xmax=nc-0.5)
>              self.set_ylim(ymin=nr-0.5, ymax=-0.5)
> Index: matplotlib/examples/pylab_examples/masked_demo.py
> ===================================================================
> --- matplotlib/examples/pylab_examples/masked_demo.py    (revision 6123)
> +++ matplotlib/examples/pylab_examples/masked_demo.py    (working copy)
> @@ -1,4 +1,4 @@
> -#!/bin/env python
> +#!/usr/bin/env python
>  '''
>  Plot lines with points masked out.
> 
> Index: matplotlib/examples/misc/rec_groupby_demo.py
> ===================================================================
> --- matplotlib/examples/misc/rec_groupby_demo.py    (revision 6123)
> +++ matplotlib/examples/misc/rec_groupby_demo.py    (working copy)
> @@ -2,7 +2,7 @@
>  import matplotlib.mlab as mlab
> 
> 
> -r = mlab.csv2rec('data/aapl.csv')
> +r = mlab.csv2rec('../data/aapl.csv')
>  r.sort()
> 
>  def daily_return(prices):
> 


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to