在学习官方文档的时候,对这个做了一个简单的探究
代码类容如下:
leg.get_frame().set_alpha(0.1)
具体展现:
import matplotlib.pyplot as plt
import numpy as np
ax = plt.subplot(111)
t1 = np.arange(0.0, 1.0, 0.01)
for n in [1, 2, 3, 4]:
plt.plot(t1, t1 ** n, label="n=%d" % n)
leg = plt.legend(loc='best', ncol=4, mode="expand", shadow=True)
leg.get_frame().set_alpha(0.5)
plt.show()
对比图:
代码:
import matplotlib.pyplot as plt
import numpy as np
plt.figure(figsize=(6, 6.5))
for i in range(4):
ax = plt.subplot(221+i)
alpha = 0.98 / 4 * i + 0.01
ax.set_title('%.3f' % alpha)
t1 = np.arange(0.0, 1.0, 0.01)
for n in [1, 2, 3, 4]:
plt.plot(t1, t1 ** n, label="n=%d" % n)
leg = plt.legend(loc='best', ncol=4, mode="expand", shadow=True)
leg.get_frame().set_alpha(alpha)
plt.savefig('1.png')
plt.show()