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

Skip to content

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

Closed
@Bilokin

Description

@Bilokin

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions