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]: linelengths parameter of Axes.eventplot does not accept delta units #27479

Open
@QuLogic

Description

@QuLogic

Bug summary

Based on#27466, thelinelengths parameter ofAxes.eventplot does not accept delta units, such asdatetime.timedelta. This should work, aslinelengths is something similar towidth inbar.

Code for reproduction

fig,ax=plt.subplots(layout="constrained")x_dates1=np.array(    [datetime.datetime(2020,6,30),datetime.datetime(2020,7,22),datetime.datetime(2020,8,3),datetime.datetime(2020,9,14),],dtype=np.datetime64)np.random.seed(19680801)start_date=datetime.datetime(2020,7,1)end_date=datetime.datetime(2020,10,15)date_range=end_date-start_datedates1=start_date+np.random.rand(30)*date_rangedates2=start_date+np.random.rand(10)*date_rangedates3=start_date+np.random.rand(50)*date_rangecolors= ['C1','C2','C3']lineoffsets=np.array([datetime.datetime(2020,7,1),datetime.datetime(2020,7,15),datetime.datetime(2020,8,1)],dtype=np.datetime64)linelengths= [datetime.timedelta(days=5),datetime.timedelta(days=2),datetime.timedelta(days=3)]ax.eventplot([dates1,dates2,dates3],colors=colors,lineoffsets=lineoffsets,linelengths=linelengths)

Actual outcome

Traceback (most recent call last):  File"/home/elliott/code/matplotlib/lib/matplotlib/axis.py", line1766, inconvert_units    ret=self.converter.convert(x,self.units,self)  File"/home/elliott/code/matplotlib/lib/matplotlib/dates.py", line1829, inconvertreturnself._get_converter().convert(*args,**kwargs)  File"/home/elliott/code/matplotlib/lib/matplotlib/dates.py", line1757, inconvertreturn date2num(value)  File"/home/elliott/code/matplotlib/lib/matplotlib/dates.py", line449, indate2num    d= d.astype('datetime64[us]')ValueError:Could not convert object to NumPy datetimeThe above exception was the direct cause of the following exception:Traceback (most recent call last):  File"/home/elliott/code/matplotlib/foo.py", line31, in<module>    ax.eventplot([dates1, dates2, dates3],colors=colors,  File"/home/elliott/code/matplotlib/lib/matplotlib/__init__.py", line1472, ininnerreturn func(  File"/home/elliott/code/matplotlib/lib/matplotlib/axes/_axes.py", line1353, ineventplot    lineoffsets, linelengths=self._process_unit_info(  File"/home/elliott/code/matplotlib/lib/matplotlib/axes/_base.py", line2566, in_process_unit_inforeturn [axis_map[axis_name].convert_units(data)  File"/home/elliott/code/matplotlib/lib/matplotlib/axes/_base.py", line2566, in<listcomp>return [axis_map[axis_name].convert_units(data)  File"/home/elliott/code/matplotlib/lib/matplotlib/axis.py", line1768, inconvert_unitsraise munits.ConversionError('Failed to convert value(s) to axis'matplotlib.units.ConversionError:Failed to convert value(s) to axis units: [datetime.timedelta(days=5), datetime.timedelta(days=2), datetime.timedelta(days=3)]

Expected outcome

The plot should work, with some kind of date-based scale on the vertical axis.

Additional information

No response

Operating system

No response

Matplotlib Version

a2a2809

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

git checkout

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp