if isinstance(x, str) and x == 'None':
This is not considered best practice for testing for strings, because
the pythonic philosophy is "if it walks like a duck and talks like a
duck, we'll treat it like a duck", aka "duck-typing"
So matplotlib.cbook provides is_string_like
from matplotlib.cbook import is_string_like
if is_string_like(x) and x == 'None':
The implementation is:
if hasattr(obj, 'shape'): return 0 # this is a workaround
# for a bug in numeric<23.1
try: obj + ''
except (TypeError, ValueError): return 0
This basically tests for the ability to add oneself to a string, which
is a solution suggested by the Python Cookbook.