konstantint / matplotlib-venn

Area-weighted venn-diagrams for Python/matplotlib
MIT License
496 stars 67 forks source link

ValueError: cannot convert float NaN to integer #17

Closed jeanrjc closed 9 years ago

jeanrjc commented 9 years ago

Hi,

I have a ValueError, and I don't really get why.

This works:

import matplotlib_venn as mv
c = mv.venn3_unweighted([set(["A","B","C"]), 
                         set(["A","D","E","F"]),
                         set(["A","C","E"])],
                         subset_areas=(135, 409, 17397, 122, 201, 135, 122))

And this doesn't (or above 17398):

import matplotlib_venn as mv
c = mv.venn3_unweighted([set(["A","B","C"]), 
                         set(["A","D","E","F"]),
                         set(["A","C","E"])],
                         subset_areas=(135, 409, 17398, 122, 201, 135, 122))

and returns:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-90-9bf6faa539ff> in <module>()
      3                                             set(["A","D","E","F"]),
      4                                             set(["A","C","E"])],
----> 5                                             subset_areas=(135, 409, 17398, 122, 201, 135, 122))

/User/lib/python2.7/site-packages/matplotlib_venn/_util.pyc in venn3_unweighted(subsets, set_labels, set_colors, alpha, normalize_to, subset_areas, ax)
     46     (it is (1, 1, 1, 1, 1, 1, 1) by default. You are free to change it, within reason).
     47     '''
---> 48     v = venn3(subset_areas, set_labels, set_colors, alpha, normalize_to, ax)
     49     # Now rename the labels
     50     subset_ids = ['100', '010', '110', '001', '101', '011', '111']

/User/lib/python2.7/site-packages/matplotlib_venn/_venn3.pyc in venn3(subsets, set_labels, set_colors, alpha, normalize_to, ax)
    345 
    346     # Create and add patches and text
--> 347     patches = [r.make_patch() for r in regions]
    348     for (p, c) in zip(patches, colors):
    349         if p is not None:

/User/lib/python2.7/site-packages/matplotlib_venn/_region.pyc in make_patch(self)
    489                 vertices = Path.arc(a.from_angle, a.to_angle).vertices
    490             else:
--> 491                 vertices = Path.arc(a.to_angle, a.from_angle).vertices
    492                 vertices = vertices[np.arange(len(vertices) - 1, -1, -1)]
    493             vertices = vertices * a.radius + a.center

/User/lib/python2.7/site-packages/matplotlib/path.pyc in arc(cls, theta1, theta2, n, is_wedge)
    811         # number of curve segments to make
    812         if n is None:
--> 813             n = int(2 ** np.ceil((eta2 - eta1) / halfpi))
    814         if n < 1:
    815             raise ValueError("n must be >= 1 or None")

ValueError: cannot convert float NaN to integer

I used venn3_unweighted(), but with my real data, I use venn3() and the error is the same.

I have

konstantint commented 9 years ago

That's a bug indeed. Fixed. Do pip install --upgrade matplotlib_venn

jeanrjc commented 9 years ago

Ok Thanks. It works.

I still get a warning though: warnings.warn("Bad circle positioning")

What does it refer to ?

konstantint commented 9 years ago

The circles are positioned in an attempt to make sure the areas of the sets AB, BC and AC are visually correct. In certain pathological cases this is impossible and the resulting numbers are tweaked in an ad-hoc basis.

The warning is generated during that tweaking step and basically warns that you are most probably going to see an ugly picture in any case.