我在Python 3中使用最新版本的iPython Notebook来显示使用%matplotlib inline
的图表。情节中的传说没有背景,底层数字显示出来。当我使用终端或IDE创建绘图时,图例是不透明的。如何使iPython Notebook中的图例也不透明?
py.rcParams['xtick.major.pad'] = 8
py.rcParams['ytick.major.pad'] = 8
py.rcParams['lines.linewidth'] = 2
py.rcParams['legend.fontsize'] = 12
py.rcParams['legend.fancybox'] = True
py.rcParams['axes.grid'] = True
py.figure(2, figsize=(14,6))
py.subplot(1,2,1)
py.plot(t, co, label='co')
py.plot(t, co2, label='co2')
py.plot(t, ch2o, label='ch2o')
py.plot(t, hcooh, label='hcooh')
py.plot(t, ch4, label='ch4')
py.plot(t, glyox, label='glyox')
py.plot(t, c2h4o, label='c2h4o')
py.title('Cellulose Species, T = {} K'.format(Tinf))
py.xlabel('Time (s)')
py.ylabel('Mass Fraction')
py.legend(loc='best', numpoints=1)
py.subplot(1,2,2)
py.plot(t, haa, label='haa')
py.plot(t, c3h6o, label='c3h6o')
py.plot(t, hmfu, label='HMFU')
py.plot(t, lvg, label='LVG')
py.plot(t, h2, label='h2')
py.plot(t, h2o, label='h2o')
py.plot(t, char, label='char')
py.title('Cellulose Species, T = {} K'.format(Tinf))
py.xlabel('Time (s)')
py.legend(loc='best', numpoints=1)
py.show()
答案 0 :(得分:1)
试试这个:
创建图例时,请将其指定给变量,例如legend
,然后添加以下行:
legend.get_frame().set_fc('w')
legend.get_frame().set_alpha(1)
legend.set_zorder(99)
这将使图例的背景变为白色并位于线条前面。