Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore nan in hist() #59

Closed
basnijholt opened this issue May 10, 2015 · 5 comments
Closed

ignore nan in hist() #59

basnijholt opened this issue May 10, 2015 · 5 comments
Labels
type: feature A major new feature

Comments

@basnijholt
Copy link
Contributor

I tried the example

((fractal * HLine(y=0)).hist() + fractal.sample(y=0))

on my own data, but .hist() doesn't handle np.NaN values.

Traceback (most recent call last):
  File "/home/bnijholt/python/env_stable/lib/python2.7/site-packages/holoviews/ipython/display_hooks.py", line 203, in wrapped
    **kwargs)
  File "/home/bnijholt/python/env_stable/lib/python2.7/site-packages/holoviews/ipython/display_hooks.py", line 279, in layout_display
    return display_figure(fig)
  File "/home/bnijholt/python/env_stable/lib/python2.7/site-packages/holoviews/ipython/display_hooks.py", line 168, in display_figure
    figdata = renderer.figure_data(fig, figure_format)
  File "/home/bnijholt/python/env_stable/lib/python2.7/site-packages/holoviews/plotting/__init__.py", line 252, in figure_data
    fig.canvas.print_figure(bytes_io, **kw)
  File "/home/bnijholt/python/env_stable/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 2168, in print_figure
    bbox = a.get_window_extent(renderer)
  File "/home/bnijholt/python/env_stable/lib/python2.7/site-packages/matplotlib/patches.py", line 491, in get_window_extent
    return self.get_path().get_extents(self.get_transform())
  File "/home/bnijholt/python/env_stable/lib/python2.7/site-packages/matplotlib/path.py", line 518, in get_extents
    transform = transform.frozen()
  File "/home/bnijholt/python/env_stable/lib/python2.7/site-packages/matplotlib/transforms.py", line 2067, in frozen
    return blended_transform_factory(self._x.frozen(), self._y.frozen())
  File "/home/bnijholt/python/env_stable/lib/python2.7/site-packages/matplotlib/transforms.py", line 2201, in blended_transform_factory
    return BlendedAffine2D(x_transform, y_transform)
  File "/home/bnijholt/python/env_stable/lib/python2.7/site-packages/matplotlib/transforms.py", line 2148, in __init__
    assert y_transform.is_separable
AssertionError

Is it possible to make it ignore these values?

@jlstevens
Copy link
Contributor

I think this is a reasonable feature request that should be fairly easy to implement.

@jlstevens jlstevens added the type: feature A major new feature label May 11, 2015
@philippjfr
Copy link
Member

Fixed in a981515, let me know if it works for you so I can close this issue.

@basnijholt
Copy link
Contributor Author

Thanks for doing this!

This works:

z1.hist()

But this doesn't

In [6]:

z1.hist(bin_range=(1e-5, z1.data.max()))
Traceback (most recent call last):
  File "/home/bnijholt/python/env_stable/lib/python2.7/site-packages/holoviews/ipython/display_hooks.py", line 203, in wrapped
    **kwargs)
  File "/home/bnijholt/python/env_stable/lib/python2.7/site-packages/holoviews/ipython/display_hooks.py", line 279, in layout_display
    return display_figure(fig)
  File "/home/bnijholt/python/env_stable/lib/python2.7/site-packages/holoviews/ipython/display_hooks.py", line 168, in display_figure
    figdata = renderer.figure_data(fig, figure_format)
  File "/home/bnijholt/python/env_stable/lib/python2.7/site-packages/holoviews/plotting/__init__.py", line 252, in figure_data
    fig.canvas.print_figure(bytes_io, **kw)
  File "/home/bnijholt/python/env_stable/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 2168, in print_figure
    bbox = a.get_window_extent(renderer)
  File "/home/bnijholt/python/env_stable/lib/python2.7/site-packages/matplotlib/patches.py", line 491, in get_window_extent
    return self.get_path().get_extents(self.get_transform())
  File "/home/bnijholt/python/env_stable/lib/python2.7/site-packages/matplotlib/path.py", line 518, in get_extents
    transform = transform.frozen()
  File "/home/bnijholt/python/env_stable/lib/python2.7/site-packages/matplotlib/transforms.py", line 2067, in frozen
    return blended_transform_factory(self._x.frozen(), self._y.frozen())
  File "/home/bnijholt/python/env_stable/lib/python2.7/site-packages/matplotlib/transforms.py", line 2201, in blended_transform_factory
    return BlendedAffine2D(x_transform, y_transform)
  File "/home/bnijholt/python/env_stable/lib/python2.7/site-packages/matplotlib/transforms.py", line 2148, in __init__
    assert y_transform.is_separable
AssertionError
Out[6]:
:AdjointLayout   [AdjointLayout]
   :Histogram   [Band gap]   (Frequency)

@philippjfr
Copy link
Member

Presumably that's because

z1.data.max()

Returns np.NaN, so I think that behavior is desired, you provided an invalid range so it will complain. It should probably complain long before it gets to plotting but if you want to do that then just use:

z1.hist(bin_range=(1e-5, np.nanmax(z1.data)))

@basnijholt
Copy link
Contributor Author

Yes, works like a charm 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature A major new feature
Projects
None yet
Development

No branches or pull requests

3 participants