Saturday, December 13, 2008

使用Matplotlib绘图时获得半透明的Legend

下面代码给出了做法。很简单,不过解决了绘制Amino中的性能曲线的一个小问题。


import matplotlib.pyplot as plt

import numpy as np

import matplotlib.pyplot as plt



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=2, mode="expand", shadow=True, fancybox=True)

leg.get_frame().set_alpha(0.5)



plt.show()



代码来自Matplotlib的What's New,效果图也在那里

0 comments: