Matlab怎么旋转器件,matlab如何旋转图例

来源

写论文时,由于图形位置占满了,想把图例旋转90°,使图形更紧凑。

matlab图例拆分成两个多个分别显示

已经解决了图例一分为二的方法,这里专注于图例旋转。

鸣谢

感谢 Sai Sri Pathuri 解决 我在matlab论坛提出的问题。如下代码是 Sai Sri Pathuri 提供,并非 并非 并非 我原创。

代码

% create a sample plot

h1 = plot(1:5);

% add legend to the graph

[legend_handle, icons] = legend('Sample legend');

% disable the box around the legend object

set(legend_handle, 'Box', 'off')

% get the current position of the legend object

leg_pos=get(legend_handle,'position');

% assign the required position of the legend to a new variable

new_leg_pos=[.7 0.6 .2 leg_pos(4)+.2] ;

% Get current line data (horizontal line)

xd = icons(2).XData;

yd = icons(2).YData;

% Swap X and Y data for line (make vertical line)

icons(2).XData = yd;

icons(2).YData = xd;

% Rotate and reposition the text

set(icons(1),'rotation',90)

icons(1).Position = [0.5 0.4 0];

% Adjust legend size to accomodate changes.

set(legend_handle,'position',new_leg_pos);

实例图形

5873a099ac41965ae08e9a445c8c16ab.png

0b3c6313bf38a68bf0a5b799ab56d550.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值