You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The default reduce_C_function (np.mean) returns np.nan for size 0 sequence and hexbin does not cause Error. However, the default mincnt (=0) and reduce_C_function=np.max can cause Error for some gridsize & extent settings due to zero-sized sequence.
Code for reproduction
importnumpyasnpimportmatplotlib.pyplotaspltx=np.array([0. , 1. , 2. , 0.5, 1.5, 2.5, 0. , 1. , 2. ])
y=np.array([0. , 0. , 0. , 0.8660254 , 0.8660254 ,
0.8660254 , 1.73205081, 1.73205081, 1.73205081])
extent=(0,2.5,0,np.sqrt(3))
C=np.arange(x.size)
gridsize=(3,1)
plt.hexbin(x,y,C, extent=extent, reduce_C_function=np.max, gridsize=gridsize)
# ValueError: zero-size array to reduction operation maximum which has no identity
Actual outcome
ValueError will be raised by numpy max(), which cannot accept zero sized sequence.
Apparently, the matplotlib versions>=3.8.0 would have the behavior but versions<3.8.0 do not.
The default reduce_C_function (np.mean) returns np.nan for size 0 sequence and it does not cause Error. However, the default mincnt (None and mincnt=0 is assigned for None) and reduce_C_function=np.max can cause Error due to zero-sized sequence. The old versions use 'len(acc) > mincnt' comparison and it kicks size 0 sequence by default. However, the new version uses 'len(acc) >= mincnt' comparison but the default mincnt is still 0. Hence, 0 sized input is not kicked and numpy max() like functions raise Error. It can be fixed by mincnt=0.5 (1 is not compatible with the old matplotlib versions).
If this is a desired (planed) behavior, it would be nice if the documents (release notes) describe the behavior explicitly. At least my program won't work before fixing the problem, and I have to read the codes and their commit history to find the root cause.
Best regards
Operating system
Windows and Ubuntu
Matplotlib Version
3.8.0
Matplotlib Backend
Qt5Agg or Agg
Python version
3.11.4
Jupyter version
NA
Installation
pip
The text was updated successfully, but these errors were encountered:
Bug summary
The default reduce_C_function (np.mean) returns np.nan for size 0 sequence and hexbin does not cause Error. However, the default mincnt (=0) and reduce_C_function=np.max can cause Error for some gridsize & extent settings due to zero-sized sequence.
Code for reproduction
Actual outcome
ValueError will be raised by numpy max(), which cannot accept zero sized sequence.
Expected outcome
No error is raised.
Additional information
This bug/new specification has been introduced by
fcda8c8
Apparently, the matplotlib versions>=3.8.0 would have the behavior but versions<3.8.0 do not.
The default reduce_C_function (np.mean) returns np.nan for size 0 sequence and it does not cause Error. However, the default mincnt (None and mincnt=0 is assigned for None) and reduce_C_function=np.max can cause Error due to zero-sized sequence. The old versions use 'len(acc) > mincnt' comparison and it kicks size 0 sequence by default. However, the new version uses 'len(acc) >= mincnt' comparison but the default mincnt is still 0. Hence, 0 sized input is not kicked and numpy max() like functions raise Error. It can be fixed by mincnt=0.5 (1 is not compatible with the old matplotlib versions).
plt.hexbin(x,y,C, extent=extent, reduce_C_function=np.max, gridsize=gridsize, mincnt=0.5)
If this is a desired (planed) behavior, it would be nice if the documents (release notes) describe the behavior explicitly. At least my program won't work before fixing the problem, and I have to read the codes and their commit history to find the root cause.
Best regards
Operating system
Windows and Ubuntu
Matplotlib Version
3.8.0
Matplotlib Backend
Qt5Agg or Agg
Python version
3.11.4
Jupyter version
NA
Installation
pip
The text was updated successfully, but these errors were encountered: