Skip to content

fix: allow None for addplot and alines kwargs in plot()#696

Open
Jo2234 wants to merge 1 commit intomatplotlib:masterfrom
Jo2234:fix/allow-none-for-addplot-alines
Open

fix: allow None for addplot and alines kwargs in plot()#696
Jo2234 wants to merge 1 commit intomatplotlib:masterfrom
Jo2234:fix/allow-none-for-addplot-alines

Conversation

@Jo2234
Copy link

@Jo2234 Jo2234 commented Feb 28, 2026

Summary

Fix addplot and alines kwarg validators to accept None, matching their documented default values.

Problem

When users conditionally build plot arguments and explicitly pass addplot=None or alines=None, a TypeError is raised because the validators don't accept None:

# This raises TypeError even though None is the documented default
mpf.plot(df, type='candle', volume=True, addplot=None, alines=None)
TypeError: kwarg "addplot" validator returned False for value: "None"
TypeError: kwarg "alines" validator returned False for value: "None"

This is a common pattern when conditionally building kwargs:

adp = build_addplots()  # may return None
tradeline = build_lines()  # may return None
mpf.plot(df, addplot=adp, alines=tradeline)  # crashes if either is None

Fix

-  'Validator': lambda value: isinstance(value,dict) or (isinstance(value,list) and all([isinstance(d,dict) for d in value]))
+  'Validator': lambda value: value is None or isinstance(value,dict) or (isinstance(value,list) and all([isinstance(d,dict) for d in value]))

-  'Validator': lambda value: _alines_validator(value)
+  'Validator': lambda value: value is None or _alines_validator(value)

Both kwargs already have 'Default': None and the plot() function body already checks for None (lines 421, 659, 740), so this fix makes the validators consistent.

Fixes #681

The validators for 'addplot' and 'alines' kwargs rejected None values,
even though None is the documented default. This caused a TypeError
when users explicitly passed addplot=None or alines=None (e.g. when
conditionally building plot arguments).

The fix adds 'value is None or' to both validators so they accept
None, matching the Default value and the existing None-checks in
the plot() function body (lines 421, 740, 659).

Fixes matplotlib#681
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mplfinance default values rise error in plot function

1 participant