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

Skip to content

[Bug]: using set_offsets on scatter object raises TypeError #21803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gtimoshaz opened this issue Nov 29, 2021 · 5 comments · Fixed by #21818
Closed

[Bug]: using set_offsets on scatter object raises TypeError #21803

gtimoshaz opened this issue Nov 29, 2021 · 5 comments · Fixed by #21818

Comments

@gtimoshaz
Copy link

gtimoshaz commented Nov 29, 2021

Bug summary

plt.scatter can accept datetime as arguments, but set_offsets method of it's returns cannot.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 10)
y = np.sin(x)
d = x * np.timedelta64(24, 'h') + np.datetime64('2021-11-29')

sc = plt.scatter(d, y) # shows a plot
sc.set_offsets(list(zip(d, y))) # clears the plot so it becomes just white square

Actual outcome

The scatters just disappear if you use other timedelta64 units than D, also if you use other date unit, than day.

Expected outcome

Excepted outcome is to update positions of scatters

Additional information

No response

Operating system

Arch

Matplotlib Version

3.5.0

Matplotlib Backend

Qt5Agg, 'module://ipympl.backend_nbagg'

Python version

Python 3.9.6

Jupyter version

3.1.7

Installation

conda

@jklymak
Copy link
Member

jklymak commented Nov 29, 2021

Thanks, but this has been fixed, at least as of 3.5, so I'll close.

@jklymak jklymak closed this as completed Nov 29, 2021
@gtimoshaz
Copy link
Author

gtimoshaz commented Nov 29, 2021

Well, I've just updated to 3.5.0 and the bug is still here with the exact same error.

UPD updating numpy to 1.21.4 helped
UPD2 it seems that it works for days, but not for hours. So if I replace timedelta64(1, 'D') with timedelta64(24, 'h') the code still does not work

@jklymak
Copy link
Member

jklymak commented Nov 30, 2021

Please update the issue with the non working code and the error message. Thanks!

@gtimoshaz
Copy link
Author

Done

@jklymak
Copy link
Member

jklymak commented Nov 30, 2021

Agreed - set_offset coerces to float, which of course gets rid of your datetime. As a work around, you can convert to float before passing: list(zip(mdates.date2num(d), y)) but this should also be fixed on our side. Thanks!

@QuLogic QuLogic added this to the v3.5.1 milestone Dec 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants