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

Rectangle patch added to a datetime x-axis is plotted with the wrong width #10349

Closed
@Khris777

Description

@Khris777

Bug report

Bug summary

When adding aRectangle patch to a plot with a datetime x-axis the width of the patch is plotted wrong.

Code for reproduction

import pandas as pdimport matplotlib.pyplot as mppimport matplotlib.patches as patchesimport datetimedata = pd.DataFrame({"Timestamp":pd.date_range(start=datetime.datetime(2018,1,30,0,0,0),end=datetime.datetime(2018,2,8,0,0,0),freq='d'),"Requests":[5,4,7,3,5,4,5,6,7,8]})fig,ax = mpp.subplots()ax.plot(data.Timestamp,data.Requests)ax.add_patch(patches.Rectangle((datetime.datetime(2018,2,2,0,0,0),ax.get_ylim()[0]),datetime.datetime(2018,2,2,0,0,0)+datetime.timedelta(days=2),ax.get_ylim()[1]))fig.show()

Actual outcome
I'm expecting a patch with a width of two days to appear on the plot, instead the patch fills the whole plot to the right rim.

Callingax.patches[0].get_width() correctly returnsdatetime.datetime(2018, 2, 4, 0, 0).

It doesn't matter if you usedatetime.datetime,np.datetime64, orpd.Timestamp, the results are the same.

EDIT: To get the correct width of two days, width really just has to set to 2.

Matplotlib version

  • Operating system: Windows 10
  • Matplotlib version: 2.1.2
  • Matplotlib backend: Qt5Agg
  • Python version: 3.6.4
  • Other libraries: Pandas 0.22.0, Numpy 1.13.3

Libraries installed with Conda, channels: defaults, conda-forge, anaconda-fusion

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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