Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug]: Missing values cause exception in errorbar plot #23330

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

Closed
Bilokin opened this issue Jun 23, 2022 · 1 comment · Fixed by #23333
Closed

[Bug]: Missing values cause exception in errorbar plot #23330

Bilokin opened this issue Jun 23, 2022 · 1 comment · Fixed by #23333
Milestone

Comments

@Bilokin
Copy link

Bilokin commented Jun 23, 2022

Bug summary

Hello,

the matplotlib handling of missing values has changed in between versions 3.5.2 and 3.2.1.
If one provides a numpy array with np.nan to the matplotlib function errorbar, one would receive an exception in the newest tag, instead of a plot with missing values like in the earlier versions.
The text of exception is misleading, because it does not say anything about NaN values.
Preferable handling of NaNs is to skip the point as it was before.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1,1)
centers = [0.75, 1.25, 1.75, 2.25, 2.75, 3.25, 4.0]
values = np.array([ 3.85112844e-03,  1.97134719e-02,  7.62180268e-02, -8.40533060e+00,
             np.nan,             np.nan, -0.00000000e+00])
errors = np.array([9.92596526e-04, 3.54076042e-03, 2.44678382e-01,
             1.66428811e+02,
           np.nan,            np.nan, 0.00000000e+00])
ax.errorbar(centers, values, errors)

Actual outcome

    ax.errorbar(bin_centers,
  File "/cvmfs/belle.cern.ch/el7/externals/v01-11-00/Linux_x86_64/common/lib/python3.8/site-packages/matplotlib/__init__.py", line 1412, in inner
    return func(ax, *map(sanitize_sequence, args), **kwargs)
  File "/cvmfs/belle.cern.ch/el7/externals/v01-11-00/Linux_x86_64/common/lib/python3.8/site-packages/matplotlib/axes/_axes.py", line 3467, in errorbar
    barcols.append(lines_func(
  File "/cvmfs/belle.cern.ch/el7/externals/v01-11-00/Linux_x86_64/common/lib/python3.8/site-packages/matplotlib/__init__.py", line 1412, in inner
    return func(ax, *map(sanitize_sequence, args), **kwargs)
  File "/cvmfs/belle.cern.ch/el7/externals/v01-11-00/Linux_x86_64/common/lib/python3.8/site-packages/matplotlib/axes/_axes.py", line 1063, in hlines
    minx = min(xmin.min(), xmax.min())
  File "/cvmfs/belle.cern.ch/el7/externals/v01-11-00/Linux_x86_64/common/lib/python3.8/site-packages/numpy/ma/core.py", line 5700, in min
    result = self.filled(fill_value).min(
  File "/cvmfs/belle.cern.ch/el7/externals/v01-11-00/Linux_x86_64/common/lib/python3.8/site-packages/numpy/core/_methods.py", line 43, in _amin
    return umr_minimum(a, axis, None, out, keepdims, initial, where)
TypeError: '<=' not supported between instances of 'float' and 'str'

Expected outcome

A plot with missing points
image

Additional information

No response

Operating system

Ubuntu

Matplotlib Version

3.5.2

Matplotlib Backend

TkAgg

Python version

Python 3.8.8

Jupyter version

3.1.2

Installation

pip

@jklymak
Copy link
Member

jklymak commented Jun 23, 2022

This bisects to 8cd22b4 #19526 which is suspiciously long ago, but... ping @anntzer

@QuLogic QuLogic added this to the v3.5.3 milestone Jun 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants