How to address multiple spines in matplotlib 3.5?

Viewed 393

The documentation here says that I can address multiple spines at once by passing in a list like so:

spines[['top','right']].set_visible(false)

I wanted to set the linewidth of my spines so I wrote

panel2.spines[["top","bottom"]].set_linewidth(0.72)

and got a TypeError: unhashable type: 'list'. I don't understand the issue.

Here is a minimal working example

import matplotlib.pyplot as plt 
import matplotlib.patches as mplpatches
import numpy as np 

plt.figure( figsize=(1,1) )

panel1=plt.axes( [0.1,0.1,0.5,0.5] )
panel1.spines[["top","bottom"]].set_linewidth(2)

plt.show()

Where replacing the list with just "top" or "bottom" string works.

1 Answers

Similar to the suggestion by @JohanC:

import matplotlib.pyplot as plt 
import matplotlib.patches as mplpatches
import numpy as np 

plt.figure( figsize=(1,1) )

panel1=plt.axes( [0.1,0.1,0.5,0.5] )
# Specify each side independently.
panel1.spines['top'].set_linewidth(2)
panel1.spines['bottom'].set_linewidth(2)

plt.show()

Reference:
How to remove the frame from a Matplotlib figure in Python

Related