I think the docs are fine, but is there a way to programmatically check? For example I have am trying to use the same set of keywords inherited from the line plot and I want to keep the ones that apply (color) and cull the ones that don’t apply (linewidth).
I was just nerd sniping myself trying to figure out a general way to do this!
At the very least for pie you can look at the docs for what artist is returned and do that manually. But it’d be nice to get the information automatically. However, that’s a bit tricky because matplotlib doesn’t have any type annotations, so I think it’d need to be directly extracted from the docstrings.
import inspect
from collections import Iterable
from matplotlib.artist import ArtistInspector
# sometimes matplotlib returns a tuple/list of objects; just get the first
def get_root(obj):
if isinstance(obj, Iterable):
return traverse(obj[0])
return obj
valid_kwds = {
chart: ArtistInspector(
get_root(getattr(plt, chart)([0], [0]))
).get_setters() + list(sig.parameters.keys())
for chart in ["plot", "bar", "pie", "scatter"]
}