pbfy0 / visvis

Automatically exported from code.google.com/p/visvis
Other
0 stars 0 forks source link

Axes range calculation incorrect if data has NaN #61

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. In visvis\examples\embeddingInQt4.py add the line
import numpy as np
and change line 60 from 
vv.plot([1,2,3,1,6]) to vv.plot([0.5,2.,3.,np.nan,3.,1.,6.])
2. Run the example. Press "Push me" for the plot to appear.
3. Examine the plot

What is the expected output? What do you see instead?

The correct y range for [0.5,2.,3.,np.nan,3.,1.,6.] is [0.5, 6.], however the 
plot has selected a default choice [0.,1.] .

What version of the product are you using? On what operating system?
visvis 1.7
Python 2.6
Pyside
Win7 x64
Qt 4.7.4

Please provide any additional information below.

The choice seems to be to fix Line._GetLimits to return a range that respects 
NaNs, or fix Axes.SetLimits to correctly recover from range=[nan,nan].

In Line._GetLimits I made the following change, but it may not be a best 
implementation for the full generality and architecture of visvis.
 #x1, x2 = self._points[:,0].min(), self._points[:,0].max()
 #y1, y2 = self._points[:,1].min(), self._points[:,1].max()
 #z1, z2 = self._points[:,2].min(), self._points[:,2].max()
 x1, x2 = np.nanmin(self._points[:,0]), np.nanmax(self._points[:,0])
 y1, y2 = np.nanmin(self._points[:,1]), np.nanmax(self._points[:,1])
 z1, z2 = np.nanmin(self._points[:,2]), np.nanmax(self._points[:,2])

The fix above is consistent with Mesh._GetLimits, for example, that takes the 
approach of managing nans within object. 

(Axes.SetLimits does test for NaN, but if found, reverts to default ranges.)

Original issue reported on code.google.com by owe...@hotmail.com on 3 Oct 2012 at 3:39

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 6f9290ee940c.

Original comment by rschr...@gmail.com on 5 Oct 2012 at 1:32

GoogleCodeExporter commented 9 years ago
This looks like the right place to fix it to me.  I've pushed a change that is 
a slight variation on your patch.  Thanks!

As I was playing with this, I saw that visvis isn't doing such a good job 
plotting NaNs or masked arrays.  We can discuss that this issue #62.

Original comment by rschr...@gmail.com on 5 Oct 2012 at 1:36

GoogleCodeExporter commented 9 years ago
Good to learn about np.nanmin and np.nanmax! 

Original comment by almar.klein@gmail.com on 5 Oct 2012 at 8:59

GoogleCodeExporter commented 9 years ago
I didn't fix this correctly.
>>> vv.plot([1,2,3,np.nan], [1,2,3,10], ms='.')
gives a y range of [1,10] instead of [1,3].  Ironically, this used to be 
handled correctly in Mesh._GetLimits, but I took it out that bit of code 
because I didn't understand what it was doing.  I'll see if I can fix it this 
evening.

Original comment by rschr...@gmail.com on 5 Oct 2012 at 6:39

GoogleCodeExporter commented 9 years ago
I've just pushed a commit that should fix these things up. This version will 
also not get confused by infinities.

Almar, I haven't closed this since I'd like you to take a look at it, to double 
check me.  Also, there's two additional things worth a look:

1) The code in Line and Mesh._GetLimits() is very similar, but part of the code 
for Mesh is within a try / except Exception: block.  If we're expecting an 
exception, we should make add this block to Line (and update it to mention a 
specific exception).  Otherwise, I'd recommend taking the block out, for 
clarity.

2) I looked through the other _GetLimits() methods.  Most of them are okay, I 
think, but you should take a look at bar and boxplot, since they might have 
similar problems.  (I'm unfamiliar with both of them.)

Original comment by rschr...@gmail.com on 7 Oct 2012 at 11:29

GoogleCodeExporter commented 9 years ago
Looks good.

I fixed bar and boxplot. For both, I ended up checking for invalid values at 
initialization, so the visualization handles it nicely too.

For the Mesh I think this is much harder, and probably less of a problem; I can 
more easily see people try to plot/barplot/boxplot some invalid data then 
trying to make a mesh of it.

As for the line, lets figure out how to deal with that in issue 62.

Original comment by almar.klein@gmail.com on 8 Oct 2012 at 8:23

GoogleCodeExporter commented 9 years ago

Original comment by almar.klein@gmail.com on 8 Oct 2012 at 8:23