What I expected to happen:
I expected it to hide right and left spines
What actually happened:
5 # Add your code here ----> 6 ax.spines["right","left"].set_visible(False) 7 ax.legend(loc='upper right') 8 ax.set_title('Percentage of Biology Degrees Awarded By Gender') KeyError: ('right', 'left')
When I got the above error, I tried passing a single argument as given in the lesson. But I ended up writing four lines. As I was looking for a more efficient way to hide all spines so I decided to match my answer with DQ’s answer. As expected, I saw a more efficient answer but I didn’t understand it completely especially the reason and need behind the two iterator keys in the loop. Can someone please explain it to me. The only thing I understand is that axes contain a spines object dictionary so yes there exists a possibility to iterate over it and ax.spines.items() gives us a list of tuples(if I am not wrong).
for key,spine in ax.spines.items(): spine.set_visible(False)