I am trying to insert annotations into the subplots of a Seaborn facet grid. From the Seaborn facet grid documentation we have an example containing:
for (row_val, col_val), ax in g.axes_dict.items():
if row_val == "Lunch" and col_val == "Female":
ax.set_facecolor(".95")
I inserted the following into my code to see if it works. My plot object name is grid
rather than g
:
for ax in grid.axes_dict.items():
ax.set_facecolor(".95")
But it gives me the error where it claims the object in question doesn’t have the set_facecolor attribute:
AttributeError: 'tuple' object has no attribute 'set_facecolor'
I checked the object’s attributes with dir() and sure enough the attributes and methods of a matplotlib Axes object, which I was expecting, were not listed. This is what I got:
for ax in grid.axes_dict.items():
print(dir(ax))
['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'count', 'index']
Am I interpreting the documentation wrong or missing something?