diff --git a/plotly/shapeannotation.py b/plotly/shapeannotation.py index a2323ed02d..9f1e0f7682 100644 --- a/plotly/shapeannotation.py +++ b/plotly/shapeannotation.py @@ -4,7 +4,14 @@ def _mean(x): if len(x) == 0: raise ValueError("x must have positive length") - return float(sum(x)) / len(x) + # Handle non-numeric values (e.g., date strings) + # For vline/hline, x0==x1 and y0==y1, so returning first value is correct + try: + return float(sum(x)) / len(x) + except TypeError: + # If sum fails (e.g., for date strings), return the first value + # This works because for vlines x0==x1, and for hlines y0==y1 + return x[0] def _argmin(x):