旋转MATLAB图例

时间:2014-06-24 00:23:05

标签: matlab rotation

有没有办法在绘图中旋转MATLAB图例?下图应该澄清我的要求。 LegendRotation

2 个答案:

答案 0 :(得分:1)

示例并非完全自动化,但应该让您选择正确的路线。您需要旋转包含图例的框以及带有文本./

的标签
% Example plot
plot(1:10)
h = legend('something')

% Rotate legend
set(h,'CameraUpVector', [1 0 0], 'Units','pixels','position',[460 230 25 150])

% Rotate text label
txt = findobj(h,'type','text');
set(txt,'rotation',90)

不幸的是,另存为函数会恢复'CameraUpVector'

答案 1 :(得分:1)

您需要玩定位,如果您绘制了多条线,则需要做更多工作,但以下内容适用于您的示例。

plot(1:10);  % create a dummy line
ha = legend('Plot'); %create a legend
set(ha,'Units','pixels'); % set axes unit to pixels
pos = get(ha,'Position'); % get the axes position
set(ha,'Position',[pos(1) pos(2)-pos(3) pos(4) pos(3)]); % Set the new position
hc = get(ha,'Children'); % Get the legend contents
set(hc(3),'Position',[0.5 0.6 0],'Rotation',90); % Relocate and rotate text
set(hc(2),'Xdata',[0.5 0.5],'YData',[0.1 0.5]); % rotate the line
set(hc(1),'XData',0.5,'YData',0.3); % Rotate the Marker