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

Use data argument for scatter plotting timestamps from pandas #11391

Closed
@ImportanceOfBeingErnest

Description

Bug report

Bug summary

This may be either a bug report or a feature request, depending how you view things. The issue is that you cannot use thedata argument toscatter to plot a pandas dataframeTimestamp column.

Code for reproduction

Consider the following data

import matplotlib.pyplot as pltimport pandas as pdimport numpy as np; np.random.seed(42)df = pd.DataFrame(np.random.rand(10,2), columns=["x","y"])df["time"] = pd.date_range("2018-01-01", periods=10, freq="D")

Using thedata argument, you may plot

plt.plot("x", "y", data=df)

You may equally plot

plt.plot("time", "y", data=df)

You may also scatter

plt.scatter(x="x", y="y", data=df)

However, you may not scatter the timestamps

plt.scatter(x="time", y="y", data=df)

This fails with aTypeError: invalid type promotion

Traceback (most recent call last):  File "D:/.../test/GI_scatterdataarg.py", line 40, in <module>    plt.scatter(x="time", y="y", data=df)  File "d:\...\matplotlib\lib\matplotlib\pyplot.py", line 2623, in scatter    verts=verts, edgecolors=edgecolors, data=data, **kwargs)  File "d:\...\matplotlib\lib\matplotlib\__init__.py", line 1775, in inner    return func(ax, *args, **kwargs)  File "d:\...\matplotlib\lib\matplotlib\axes\_axes.py", line 3982, in scatter    offsets = np.column_stack([x, y])  File "D:\...\matplotlib\lib\site-packages\numpy\lib\shape_base.py", line 369, in column_stack    return _nx.concatenate(arrays, 1)TypeError: invalid type promotion

This is a bit surprising since you may well plot timestamps through scatter

plt.scatter(x=df.time.values, y=df.x.values)

just not through thedata argument.

Expected outcome

Given that one may plot the timestamps correctly withplot and timestamps withscatter by providing the values, it would be nice to be able to use thedata argument withscatter as well.

... and ideally withbar,fill_between etc. ;-)

Matplotlib version

  • Operating system: Win 8.1
  • Matplotlib version: master 2.2.2.post1270+g6665bc739
  • Matplotlib backend: Qt5Agg
  • Python version: 3.6
  • Jupyter version (if applicable):
  • Other libraries: Pandas 0.22.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp