写一个legend参数

plt.legend(loc=0,ncol=2, bbox_to_anchor=(num1, num2),fontsize=20,title='Test Noise',loc='best',title_fontsize=24)# ncol为标签有几列

ax.legend('boxoff')

loc:“表示位置的参数”,如下

*

'best'         : 0, (only implemented for axes legends)(自适应方式)
'upper right'  : 1,
'upper left'   : 2,
'lower left'   : 3,
'lower right'  : 4,
'right'        : 5,
'center left'  : 6,
'center right' : 7,
'lower center' : 8,
'upper center' : 9,
'center'       : 10,

*

在这里插入图片描述
bbox_to_anchor:第二个表示位置的参数,用于微调图例的位置,被赋予的二元组中。

*
‘num1’用于控制legend的左右移动,值越大,越向右边移动,
‘num2’用于控制legend的上下移动,值越大,越向上移动。
*

试试效果:

#_author:Administrator
#data:2019/7/9

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(1, 11)

fig = plt.figure(1)
ax1 = plt.subplot(2, 1, 1)
ax2 = plt.subplot(2, 1, 2)
l1, = ax1.plot(x, x*x, 'r')
l2, = ax2.plot(x, x*x, 'b')

plt.legend([l1, l2], ['first', 'second'],
           loc=0,
           # ncol=2,
            bbox_to_anchor=(0.99, 0.99))
plt.show()

在这里插入图片描述
备注:改变字体参数使用prop=font_set

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值