Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Bug]: TypeError when plotting against list of datetime.date where 0th element of list is None #23580

Closed
Labels
Milestone
@myUsernameIsNotMyPassword

Description

Bug summary

pyplot raises an error when a list of dates starts with None.

Code for reproduction

fromdatetimeimport*frommatplotlibimportpyplotasplty= [6,2,8,3,1,8,5,3,0,7]x= [date.today()+timedelta(days=i)foriinrange(10)]x[5]=Nonex[-1]=Noneplt.plot(x,y)# worksplt.show()x[0]=Noneplt.plot(x,y)# TypeErrorplt.show()

Actual outcome

Traceback (most recent call last):  File "pyplot_test.py", line 17, in <module>    plt.plot(x, y)  File "<python_path>\lib\site-packages\matplotlib\pyplot.py", line 2769, in plot    return gca().plot(  File "<python_path>\lib\site-packages\matplotlib\axes\_axes.py", line 1634, in plot    self.add_line(line)  File "<python_path>\lib\site-packages\matplotlib\axes\_base.py", line 2288, in add_line    self._update_line_limits(line)  File "<python_path>\lib\site-packages\matplotlib\axes\_base.py", line 2311, in _update_line_limits    path = line.get_path()  File "<python_path>\lib\site-packages\matplotlib\lines.py", line 999, in get_path    self.recache()  File "<python_path>\lib\site-packages\matplotlib\lines.py", line 652, in recache    x = _to_unmasked_float_array(xconv).ravel()  File "<python_path>\lib\site-packages\matplotlib\cbook\__init__.py", line 1298, in _to_unmasked_float_array    return np.asarray(x, float)  File "<python_path>\lib\site-packages\numpy\core\_asarray.py", line 85, in asarray    return array(a, dtype, copy=False, order=order)TypeError: float() argument must be a string or a number, not 'datetime.date'

Expected outcome

plot data starting at index 1.

Additional information

No response

Operating system

windows 10

Matplotlib Version

3.5.2

Matplotlib Backend

TkAgg

Python version

3.8.2

Jupyter version

No response

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp