首页 > 解决方案 > ValueError:零大小数组到没有身份的归约操作最小值 - Seaborn

问题描述

下面的代码突然声明产生错误。它之前工作正常。我刚刚重新安装了 seaborn 包。

plt.figure(figsize=(26,16))
sns.scatterplot(
    x="tsne-2d-one", 
    y="tsne-2d-two",
    hue="label",
    palette=sns.color_palette("hls", 14),
    data=df_subset,
    legend="full",
    alpha=1,
    s=100
)

追溯:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
c:\<path>_venv\lib\site-packages\IPython\core\formatters.py in __call__(self, obj)
    339                 pass
    340             else:
--> 341                 return printer(obj)
    342             # Finally look for special method names
    343             method = get_real_method(obj, self.print_method)

c:\<path>_venv\lib\site-packages\IPython\core\pylabtools.py in <lambda>(fig)
    246 
    247     if 'png' in formats:
--> 248         png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))
    249     if 'retina' in formats or 'png2x' in formats:
    250         png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))

c:\<path>_venv\lib\site-packages\IPython\core\pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)
    130         FigureCanvasBase(fig)
    131 
--> 132     fig.canvas.print_figure(bytes_io, **kw)
    133     data = bytes_io.getvalue()
    134     if fmt == 'svg':

c:\<path>_venv\lib\site-packages\matplotlib\backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
   2191                            else suppress())
   2192                     with ctx:
-> 2193                         self.figure.draw(renderer)
   2194 
   2195                     bbox_inches = self.figure.get_tightbbox(

c:\<path>_venv\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     39                 renderer.start_filter()
     40 
---> 41             return draw(artist, renderer, *args, **kwargs)
     42         finally:
     43             if artist.get_agg_filter() is not None:

c:\<path>_venv\lib\site-packages\matplotlib\figure.py in draw(self, renderer)
   1861 
   1862             self.patch.draw(renderer)
-> 1863             mimage._draw_list_compositing_images(
   1864                 renderer, self, artists, self.suppressComposite)
   1865 

c:\<path>_venv\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    129     if not_composite or not has_images:
    130         for a in artists:
--> 131             a.draw(renderer)
    132     else:
    133         # Composite any adjacent images together

c:\<path>_venv\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     39                 renderer.start_filter()
     40 
---> 41             return draw(artist, renderer, *args, **kwargs)
     42         finally:
     43             if artist.get_agg_filter() is not None:

c:\<path>_venv\lib\site-packages\matplotlib\cbook\deprecation.py in wrapper(*inner_args, **inner_kwargs)
    409                          else deprecation_addendum,
    410                 **kwargs)
--> 411         return func(*inner_args, **inner_kwargs)
    412 
    413     return wrapper

c:\<path>_venv\lib\site-packages\matplotlib\axes\_base.py in draw(self, renderer, inframe)
   2746             renderer.stop_rasterizing()
   2747 
-> 2748         mimage._draw_list_compositing_images(renderer, self, artists)
   2749 
   2750         renderer.close_group('axes')

c:\<path>_venv\lib\site-packages\matplotlib\image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
    129     if not_composite or not has_images:
    130         for a in artists:
--> 131             a.draw(renderer)
    132     else:
    133         # Composite any adjacent images together

c:\<path>_venv\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     39                 renderer.start_filter()
     40 
---> 41             return draw(artist, renderer, *args, **kwargs)
     42         finally:
     43             if artist.get_agg_filter() is not None:

c:\<path>_venv\lib\site-packages\matplotlib\collections.py in draw(self, renderer)
    929     def draw(self, renderer):
    930         self.set_sizes(self._sizes, self.figure.dpi)
--> 931         Collection.draw(self, renderer)
    932 
    933 

c:\<path>_venv\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     39                 renderer.start_filter()
     40 
---> 41             return draw(artist, renderer, *args, **kwargs)
     42         finally:
     43             if artist.get_agg_filter() is not None:

c:\<path>_venv\lib\site-packages\matplotlib\collections.py in draw(self, renderer)
    383             else:
    384                 combined_transform = transform
--> 385             extents = paths[0].get_extents(combined_transform)
    386             if (extents.width < self.figure.bbox.width
    387                     and extents.height < self.figure.bbox.height):

c:\<path>_venv\lib\site-packages\matplotlib\path.py in get_extents(self, transform, **kwargs)
    601                 xys.append(curve([0, *dzeros, 1]))
    602             xys = np.concatenate(xys)
--> 603         return Bbox([xys.min(axis=0), xys.max(axis=0)])
    604 
    605     def intersects_path(self, other, filled=True):

c:\<path>_venv\lib\site-packages\numpy\core\_methods.py in _amin(a, axis, out, keepdims, initial, where)
     32 def _amin(a, axis=None, out=None, keepdims=False,
     33           initial=_NoValue, where=True):
---> 34     return umr_minimum(a, axis, None, out, keepdims, initial, where)
     35 
     36 def _sum(a, axis=None, dtype=None, out=None, keepdims=False,

ValueError: zero-size array to reduction operation minimum which has no identity

注:df_subset不是空的,我查过。它有 3 列 "tsne-2d-one"、"tsne-2d-two"、"label" "tsne-2d-one"、"tsne-2d-two" 包含浮点数据类型值
"label" 具有字符串/对象数据类型值

样本数据:

tsne-2d-one,tsne-2d-two,label
-14.02892,-24.425629,A_A-A
-13.000096,-23.515806,A_A-A
-14.205202,-24.717735,A_A-A
-15.494256,-25.991783,A_A-A
-13.5905905,-23.419744,A_A-A
-13.350816,-25.939915,A_A-A
-12.438069,-24.727852,A_A-A
-13.54109,-26.080505,A_A-A
-14.834715,-26.33772,A_A-A
-13.562927,-23.37612,A_A-A
-15.59718,-24.024368,A_A-A
-14.931401,-22.854977,A_A-A
-15.655616,-24.41179,A_A-A
-15.716855,-25.620882,A_A-A
-15.219434,-23.031553,A_A-A
2.084894,-14.178911,B_B
5.5166216,-12.401592,B_B
2.0064962,-14.086351,B_B
5.5460343,1.7539215,B_B
5.002867,-13.499105,B_B
-0.13123433,0.9796202,B_B
7.7138877,-7.102608,B_B
-0.119276464,0.99467605,B_B
6.679522,1.4599445,B_B
4.96602,-13.200384,B_B
9.150655,-3.64276,B_B
10.205461,-6.4425406,B_B
9.038797,-3.5547273,B_B
7.0086393,1.1566005,B_B
9.934251,-6.873103,B_B
-11.11679,-11.341377,C_C C
-14.512915,-8.015724,C_C C
-9.953341,-11.557578,C_C C
-16.696735,-6.1155863,C_C C
-15.87594,-8.795022,C_C C
-11.377112,-14.174167,C_C C
-13.324324,-9.64841,C_C C
-11.897048,-13.814134,C_C C
-16.109194,-11.869152,C_C C
-16.046644,-8.998125,C_C C
-9.286824,-14.231626,C_C C
-12.704834,-7.5153055,C_C C
-9.349987,-13.253436,C_C C
-18.200735,-7.0271044,C_C C
-12.994204,-6.0151153,C_C C
-3.0917523,-10.06981,D_D_1
4.6217837,-10.767031,D_D_1
-3.1154654,-10.096936,D_D_1
5.0603623,1.1476644,D_D_1
3.369002,-11.283088,D_D_1
-5.780945,-7.966547,D_D_1
6.6392574,-8.486886,D_D_1
-5.7979536,-7.9725084,D_D_1
5.7012763,0.1932977,D_D_1
3.4227533,-11.3441305,D_D_1
-4.905956,-10.156104,D_D_1
5.8067675,-9.307196,D_D_1
-4.96808,-10.07095,D_D_1
6.28622,0.08598101,D_D_1
5.3993483,-9.526921,D_D_1
-11.131304,-11.375446,E_E_E
-14.445314,-8.006492,E_E_E
-9.945171,-11.480152,E_E_E
-16.731579,-6.1148796,E_E_E
-15.929554,-8.714455,E_E_E
-11.266886,-14.26166,E_E_E
-13.352065,-9.705651,E_E_E
-12.172098,-13.885426,E_E_E
-15.697548,-11.84327,E_E_E
-15.805679,-8.887896,E_E_E
-9.271222,-14.296528,E_E_E
-12.608987,-7.5177,E_E_E
-9.163923,-13.434417,E_E_E
-18.181078,-6.843873,E_E_E
-12.912988,-6.0278206,E_E_E
-1.5422965,-7.8732953,F_F_F
3.1139162,-8.750587,F_F_F
-2.028107,-7.784009,F_F_F
2.9877954,-1.4773916,F_F_F
1.7015373,-9.468788,F_F_F
-4.2344203,-5.2941556,F_F_F
5.2705426,-6.563142,F_F_F
-4.2245245,-5.600589,F_F_F
4.684833,-1.3839812,F_F_F
1.722953,-9.421918,F_F_F
-1.1982858,-4.9888654,F_F_F
3.6919396,-6.494554,F_F_F
-2.0073545,-5.178361,F_F_F
3.9441528,-2.738101,F_F_F
2.5451581,-6.1722994,F_F_F
-1.120436,-7.3399386,G_G_G_G
2.8947587,-8.145696,G_G_G_G
-1.4918948,-7.1562057,G_G_G_G
2.9648385,-1.7110974,G_G_G_G
1.5439045,-8.104277,G_G_G_G
-3.5719488,-4.901991,G_G_G_G
4.9950256,-6.279537,G_G_G_G
-3.4592612,-5.118906,G_G_G_G
4.573509,-1.6888899,G_G_G_G
1.4670004,-8.103425,G_G_G_G
-1.326964,-4.7369046,G_G_G_G
3.5509024,-6.1993237,G_G_G_G
-1.9852517,-4.7963614,G_G_G_G
3.8905938,-2.847331,G_G_G_G
2.3077533,-6.1591887,G_G_G_G
-0.6611299,14.413035,H_H
1.6424932,16.130213,H_H
-0.7701603,14.268575,H_H
2.9109209,8.180244,H_H
0.5201868,15.787671,H_H
-1.6890637,12.033475,H_H
2.8793135,16.313625,H_H
-1.6425153,11.930886,H_H
4.051731,8.0262375,H_H
0.43125528,15.851444,H_H
-0.049206052,12.614705,H_H
2.4294627,15.448605,H_H
-0.1478604,12.405042,H_H
3.6674721,8.151972,H_H
1.3558089,14.236326,H_H
-11.285671,15.540629,I_I_I
-9.562131,15.355534,I_I_I
-11.530592,15.769008,I_I_I
-13.046774,14.795182,I_I_I
-10.370458,15.011783,I_I_I
-12.224443,17.218636,I_I_I
-9.128062,16.107723,I_I_I
-12.329284,17.033316,I_I_I
-13.2455635,15.28421,I_I_I
-10.374858,15.010645,I_I_I
-11.048521,17.406425,I_I_I
-9.423859,16.605726,I_I_I
-11.302727,17.159101,I_I_I
-13.303642,14.898152,I_I_I
-10.067334,17.044987,I_I_I
19.458284,3.601622,J_J
18.161573,1.9801935,J_J
19.400095,4.1047544,J_J
16.417835,5.31509,J_J
18.94254,2.32699,J_J
18.529085,4.935621,J_J
16.578032,2.6348052,J_J
18.3073,5.0299187,J_J
16.369411,4.8019056,J_J
18.929241,2.3260906,J_J
18.18062,3.939813,J_J
16.98714,2.6408002,J_J
17.972517,4.1568704,J_J
16.239166,4.6899467,J_J
17.585348,2.8919232,J_J
-20.025661,8.026763,K_K_K
-20.538462,6.0866313,K_K_K
-19.686363,8.2460785,K_K_K
-18.748287,9.191302,K_K_K
-20.795744,7.023851,K_K_K
-17.74393,7.074227,K_K_K
-19.303535,5.2147784,K_K_K
-17.688332,7.3439727,K_K_K
-17.846653,8.789439,K_K_K
-20.777353,7.0788684,K_K_K
-18.925882,7.140357,K_K_K
-19.634892,5.644755,K_K_K
-18.661663,7.5221934,K_K_K
-18.29901,8.960838,K_K_K
-19.38654,6.43482,K_K_K
13.265437,15.976807,L_L_L
13.597595,19.052914,L_L_L
13.323307,16.138601,L_L_L
12.454088,17.811083,L_L_L
13.339949,19.46192,L_L_L
14.46764,15.587214,L_L_L
14.454488,18.439106,L_L_L
14.335033,15.607529,L_L_L
12.673782,17.41954,L_L_L
13.322454,19.446009,L_L_L
15.088017,16.46231,L_L_L
15.003597,18.347887,L_L_L
14.939234,16.422993,L_L_L
13.032935,17.582718,L_L_L
15.379603,18.11169,L_L_L
2.9893792,11.708033,M_M
4.0582185,14.155455,M_M
2.8813481,11.428211,M_M
2.9041388,8.880342,M_M
4.0471163,13.003807,M_M
-0.24122916,10.381815,M_M
3.4628656,15.878884,M_M
-0.17790422,10.348041,M_M
4.228249,8.942132,M_M
4.1144986,13.007208,M_M
1.0553777,11.241994,M_M
3.0545413,14.678934,M_M
1.1478767,10.947674,M_M
3.724015,9.194509,M_M
2.356918,13.5421915,M_M
19.131111,-8.112185,N_N_N
20.842833,-8.569077,N_N_N
19.030348,-8.294446,N_N_N
22.435442,-8.890868,N_N_N
20.483664,-8.155657,N_N_N
18.633186,-9.510608,N_N_N
20.852346,-9.7075,N_N_N
18.776926,-9.64985,N_N_N
22.413244,-9.279601,N_N_N
20.41144,-8.146459,N_N_N
19.47922,-10.565168,N_N_N
20.925726,-10.302838,N_N_N
19.37557,-10.4150505,N_N_N
22.429592,-9.683258,N_N_N
20.584888,-10.687437,N_N_N

标签: python-3.xseaborn

解决方案


问题与 3.3.1 中的 matplotlib 回归有关。

原始 seaborn 问题(已关闭)

解决方案是将 matplotlib 固定到 3.3.0 直到 3.3.2 发布,尽管 seaborn 的下一个版本将包含一个解决方法。

更新 (9/10/20):Seaborn 0.11.0 现在可用,其中包含使散点图即使使用 matplotlib 3.3.1 也可以工作的解决方法。


推荐阅读