2009-10-28 126 views
12

我使用matplotlib 0.99。matplotlib邊框寬度

我無法改變subplot的邊框寬度,我該怎麼辦?

代碼如下:

fig = plt.figure(figsize = (4.1, 2.2)) 
ax = fig.add_subplot(111) 

ax.patch.set_ linewidth(0.1) 
ax.get_frame().set_linewidth(0.1) 

最後兩行不工作,但下面的工作正常:

legend.get_frame().set_ linewidth(0.1) 

回答

21

要調整的邊界線的大小?你需要使用ax.spines [side] .set_linewidth(size)。

因此,像:

[i.set_linewidth(0.1) for i in ax.spines.itervalues()] 
+0

的感謝!這有助於。 – 2014-01-23 19:44:10

+0

哇這是一個老問題......但仍然在Python 3中使用'.values()'而不是。'itervalues()'! – 2017-10-19 18:25:02

+0

@CharlesParr,別讓我感覺老了! – Mark 2017-10-19 19:01:28

7

也許這是你在找什麼?

import matplotlib as mpl

mpl.rcParams['axes.linewidth'] = 0.1 #set the value globally