-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Open
Description
Problem
It should be possible to set the position of a violin plot to be a datetime, but currently this fails:
import datetime
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
datetimes = [
datetime.datetime(2023, 2, 10),
datetime.datetime(2023, 5, 18),
datetime.datetime(2023, 6, 6)
]
ax.violin(
[
{
'coords': datetimes,
'vals': [0.1, 0.5, 0.2],
'mean': datetimes[1],
'median': datetimes[1],
'min': datetimes[0],
'max': datetimes[-1],
'quantiles': datetimes
}
],
positions=[datetime.datetime(2020, 1, 1)]
)
Traceback (most recent call last):
File "/Users/dstansby/software/mpl/matplotlib/test.py", line 11, in <module>
ax.violin(
File "/Users/dstansby/miniforge3/envs/mpl-dev/lib/python3.12/site-packages/matplotlib/_api/deprecation.py", line 453, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/dstansby/miniforge3/envs/mpl-dev/lib/python3.12/site-packages/matplotlib/axes/_axes.py", line 9064, in violin
line_ends = [[-0.25 if side in ['both', 'low'] else 0],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unsupported operand type(s) for +: 'float' and 'datetime.datetime'
Proposed solution
No response