python画图如何调整图例位置_python legend设置不要边框的方法技巧

python legend如何设置不要边框

python matlab绘图中legend的终极用法

legend有时候挺烦人的,尽管大多时候挺好用。

基本数据:

data = rand(25)+repmat(1:25,25,1);

H = plot(data);

基本用法:

legend({'str1','str2','strn'});

高级用法1:指定legend显示的位置:

legend({'str1','str2','strn'},1);

legend({'str1','str2','strn'},2);

legend({'str1','str2','strn'},'Location','SouthEast');

可选的位置很多:

North:Inside plot box near top

South:Inside bottom

EastI:nside right

West:Inside left

NorthEast:Inside top right (default)

NorthWest:Inside top left

SouthEast:Inside bottom right

SouthWest:Inside bottom left

NorthOutside:Outside plot box near top

SouthOutside:Outside bottom

EastOutside:Outsideright

WestOutside:Outside left

NorthEastOutside:Outside top right

NorthWestOutside:Outside top left

SouthEastOutside:Outside bottom right

SouthWestOutside:Outside bottom left

Best:Least conflict with data in plot

BestOutside:Least unused space outside plot

通常,用'Best‘比较不错

高级用法2:指定显示某几条曲线的legend:

方法1:复杂到吐血

例如你有25条曲线,想显示其中1,6,11,16,21的legend,则

for i = [2:5 7:10 12:15 17:20 22:25]

set(get(get(H(i),'Annotation'),'LegendInformation'),'IconDisplayStyle','off');

end

legend('1','6','11','16','21');

方法2:简单到郁闷

H = plot(data);

legend(H([1 6 11 16 21],'1,'6','11’,'16','21');

高级用法3:legend横排

hl = legend(H([1 6 11 16 21],'1,'6','11’,'16','21');

set(hl,'Orientation','horizon')

高级用法4:不显示方框:

hl = legend(H([1 6 11 16 21],'1,'6','11’,'16','21');

set(hl,'Box','off');

另外,去掉legend边框

legend('x','y')

legend('boxoff')

写两次就好了。我最初尝试着写成legend('x','y','boxoff')是不行的。

修改legend的字体:

legend1=legend('x','y');

set(legend1,'FontName','Times New Roman','FontSize',12,'FontWeight','normal');

修改legend位置:

i=0;%i=0,自动调整最佳位置;i=1,右上;i=2,左上;i=3,左下;i=4,右下;

legend1=legend('x','y',i);

20160518

最好的说明文档,当然是帮助文档:

matlab:

doc legend

legend('hide'), legend(axes_handle,'hide') makes the legend in the current axes or the axes specified by axes_handle invisible.

legend('show'), legend(axes_handle,'show') makes the legend in the current axes or the axes specified by axes_handle visible. A legend is created if one did not exist previously. Legends created automatically are limited to depict only the first 20 lines in the plot; if you need more legend entries, you can manually create a legend for them all with legend('string1','string2',...) syntax.

legend('boxoff'), legend(axes_handle,'boxoff') removes the box from the legend in the current axes or the axes specified by axes_handle, and makes its background transparent.

legend('boxon'), legend(axes_handle,'boxon') adds a box with an opaque background to the legend in the current axes or the axes specified by axes_handle.

以上就是本次给大家分享的关于java的全部知识点内容总结,大家还可以在下方相关文章里找到相关文章进一步学习,感谢大家的阅读和支持。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值