Matlab:带有子传说的子图

马库斯

我想在子图的底部添加一个图例(2 x 2):

手动调整图
如您所见,第二行中的图表被压缩了一点,因为我手动对其进行了调整。

是否有像sublegend(...)这样的函数,或者它涉及很多编码?

资源

该脚本生成类似的子图:

%weights/weightsMV are 3 x 30 matrices
ticker = {'A','B','C'};
weights = [0.764602615068780,0.762329415005434,0.760055503116586,0.757781382654864,0.755508517683302,0.753234375934985,0.750960611173760,0.748686727917457,0.746413866211585,0.744140033854148,0.738367347277555,0.699505907957926,0.660644468638298,0.621783029318668,0.582921589999040,0.544060150679411,0.505198711359782,0.466337272040153,0.427475832720524,0.388614393400895,0.349752954081266,0.310891514761637,0.272030075442009,0.233168636122380,0.194307196802750,0.155445757483122,0.116584318163493,0.0777228788438641,0.0388614395242353,4.10026844681349e-12;0.235397384931220,0.211630038764514,0.187863021792451,0.164096524898550,0.140329000457761,0.116562305396725,0.0927953654491337,0.0690285024746061,0.0452609759124620,0.0214940798746062,0,5.55111512312733e-17,0,5.55111512312746e-17,0,3.70817036264992e-30,4.73852588619852e-30,5.76503212536727e-30,5.38827593281225e-30,2.64267976542398e-18,5.69348240589127e-18,8.74428504635863e-18,1.17950876868260e-17,0,2.75245082116940e-18,1.22032105779319e-17,9.15240793746451e-18,6.10160529699720e-18,6.10160531305980e-18,1.30251232759518e-10;1.10307850379949e-18,0.0260405462300517,0.0520814750909638,0.0781220924465861,0.104162481858937,0.130203318668290,0.156244023377106,0.182284769607937,0.208325157875953,0.234365886271246,0.261632652722445,0.300494092042074,0.339355531361703,0.378216970681332,0.417078410000960,0.455939849320589,0.494801288640218,0.533662727959847,0.572524167279476,0.611385606599105,0.650247045918734,0.689108485238363,0.727969924557991,0.766831363877620,0.805692803197249,0.844554242516878,0.883415681836507,0.922277121156136,0.961138560475765,0.999999999865655]
weightsMV = [0.304769232969962,0.313206616760582,0.299868860275947,0.286531103791370,0.273193347306773,0.259855590822158,0.246517834337581,0.233180077852984,0.219842321368369,0.206504564883792,0.193166808399157,0.179829051914561,0.166491295429983,0.153153538945368,0.139815782460772,0.126478025976194,0.113140269491579,0.0998025130069825,0.0864647565224054,0.0731270000377706,0.0597892435531935,0.0464514870685779,0.0331137305839816,0.0197759740993660,0.00643821761478891,0,0,0,0,0;0.695230767030038,0.658949751075843,0.636813620182365,0.614677489288983,0.592541358395569,0.570405227502122,0.548269096608740,0.526132965715326,0.503996834821880,0.481860703928497,0.459724573035019,0.437588442141605,0.415452311248223,0.393316180354776,0.371180049461362,0.349043918567980,0.326907787674534,0.304771656781119,0.282635525887737,0.260499394994259,0.238363264100876,0.216227133207430,0.194091002314016,0.171954871420570,0.149818740527187,0.123200747149645,0.0924005603621983,0.0616003735748407,0.0308001867873497,0;0,0.0278436321635749,0.0633175195416878,0.0987914069196473,0.134265294297658,0.169739181675720,0.205213069053679,0.240686956431690,0.276160843809752,0.311634731187711,0.347108618565824,0.382582505943834,0.418056393321794,0.453530280699856,0.489004168077866,0.524478055455826,0.559951942833888,0.595425830211898,0.630899717589858,0.666373604967971,0.701847492345930,0.737321379723992,0.772795267102002,0.808269154480064,0.843743041858024,0.876799252850355,0.907599439637802,0.938399626425159,0.969199813212650,1];

figure('name','Weights as 3D Plot');
subplot(2, 2, 1);    
plot3([weights(1, :)' weightsMV(1, :)'], [weights(2, :)' weightsMV(2, :)'], [weights(3, :)', weightsMV(3, :)']);
grid on;
xlabel(ticker(1));
ylabel(ticker(2));
zlabel(ticker(3));

subplot(2, 2, 2);
plot([weights(2, :)' weightsMV(2, :)'], [weights(3, :)' weightsMV(3, :)'])
xlabel(ticker(2));
ylabel(ticker(3));
grid on

subplot(2, 2, 3);
plot([weights(1, :)' weightsMV(1, :)'], [weights(3, :)' weightsMV(3, :)'])
xlabel(ticker(1));
ylabel(ticker(3));
grid on

subplot(2, 2, 4);
plot([weights(1, :)' weightsMV(1, :)'], [weights(2, :)' weightsMV(2, :)'])
xlabel(ticker(1));
ylabel(ticker(2));
title('Top');
grid on
legend('TS1', 'TS2', 'Location', 'SouthOutside');
majkel.mk

我设法编写了一个脚本,其脚本与所附脚本相似,并且代码尽可能少。图例元素的并排对齐比较棘手,您将需要外部脚本。我使用了在Matlab Central File Exchange上可用的gridLegend:

http://www.mathworks.com/matlabcentral/fileexchange/29248-gridlegend-a-multi-column-format-for-legends

这是您的代码,并进行了一些修改,使其可以绘制与图像上的图例相似的图例:

%weights/weightsMV are 3 x 30 matrices
ticker = {'A','B','C'};
weights = [0.764602615068780,0.762329415005434,0.760055503116586,0.757781382654864,0.755508517683302,0.753234375934985,0.750960611173760,0.748686727917457,0.746413866211585,0.744140033854148,0.738367347277555,0.699505907957926,0.660644468638298,0.621783029318668,0.582921589999040,0.544060150679411,0.505198711359782,0.466337272040153,0.427475832720524,0.388614393400895,0.349752954081266,0.310891514761637,0.272030075442009,0.233168636122380,0.194307196802750,0.155445757483122,0.116584318163493,0.0777228788438641,0.0388614395242353,4.10026844681349e-12;0.235397384931220,0.211630038764514,0.187863021792451,0.164096524898550,0.140329000457761,0.116562305396725,0.0927953654491337,0.0690285024746061,0.0452609759124620,0.0214940798746062,0,5.55111512312733e-17,0,5.55111512312746e-17,0,3.70817036264992e-30,4.73852588619852e-30,5.76503212536727e-30,5.38827593281225e-30,2.64267976542398e-18,5.69348240589127e-18,8.74428504635863e-18,1.17950876868260e-17,0,2.75245082116940e-18,1.22032105779319e-17,9.15240793746451e-18,6.10160529699720e-18,6.10160531305980e-18,1.30251232759518e-10;1.10307850379949e-18,0.0260405462300517,0.0520814750909638,0.0781220924465861,0.104162481858937,0.130203318668290,0.156244023377106,0.182284769607937,0.208325157875953,0.234365886271246,0.261632652722445,0.300494092042074,0.339355531361703,0.378216970681332,0.417078410000960,0.455939849320589,0.494801288640218,0.533662727959847,0.572524167279476,0.611385606599105,0.650247045918734,0.689108485238363,0.727969924557991,0.766831363877620,0.805692803197249,0.844554242516878,0.883415681836507,0.922277121156136,0.961138560475765,0.999999999865655]
weightsMV = [0.304769232969962,0.313206616760582,0.299868860275947,0.286531103791370,0.273193347306773,0.259855590822158,0.246517834337581,0.233180077852984,0.219842321368369,0.206504564883792,0.193166808399157,0.179829051914561,0.166491295429983,0.153153538945368,0.139815782460772,0.126478025976194,0.113140269491579,0.0998025130069825,0.0864647565224054,0.0731270000377706,0.0597892435531935,0.0464514870685779,0.0331137305839816,0.0197759740993660,0.00643821761478891,0,0,0,0,0;0.695230767030038,0.658949751075843,0.636813620182365,0.614677489288983,0.592541358395569,0.570405227502122,0.548269096608740,0.526132965715326,0.503996834821880,0.481860703928497,0.459724573035019,0.437588442141605,0.415452311248223,0.393316180354776,0.371180049461362,0.349043918567980,0.326907787674534,0.304771656781119,0.282635525887737,0.260499394994259,0.238363264100876,0.216227133207430,0.194091002314016,0.171954871420570,0.149818740527187,0.123200747149645,0.0924005603621983,0.0616003735748407,0.0308001867873497,0;0,0.0278436321635749,0.0633175195416878,0.0987914069196473,0.134265294297658,0.169739181675720,0.205213069053679,0.240686956431690,0.276160843809752,0.311634731187711,0.347108618565824,0.382582505943834,0.418056393321794,0.453530280699856,0.489004168077866,0.524478055455826,0.559951942833888,0.595425830211898,0.630899717589858,0.666373604967971,0.701847492345930,0.737321379723992,0.772795267102002,0.808269154480064,0.843743041858024,0.876799252850355,0.907599439637802,0.938399626425159,0.969199813212650,1];

figure('name','Weights as 3D Plot');

% s1, s2, s3, s4 - subplot handles
s1 = subplot(2, 2, 1);    
plot3([weights(1, :)' weightsMV(1, :)'], [weights(2, :)' weightsMV(2, :)'], [weights(3, :)', weightsMV(3, :)']);
grid on;
xlabel(ticker(1));
ylabel(ticker(2));
zlabel(ticker(3));

s2 = subplot(2, 2, 2);
plot([weights(2, :)' weightsMV(2, :)'], [weights(3, :)' weightsMV(3, :)'])
xlabel(ticker(2));
ylabel(ticker(3));
grid on

s3 = subplot(2, 2, 3);
plot([weights(1, :)' weightsMV(1, :)'], [weights(3, :)' weightsMV(3, :)'])
xlabel(ticker(1));
ylabel(ticker(3));
grid on

s4 = subplot(2, 2, 4);
% get axes handle, we will need this for legend
ax4 = plot([weights(1, :)' weightsMV(1, :)'], [weights(2, :)' weightsMV(2, :)']);
xlabel(ticker(1));
ylabel(ticker(2));
title('Top');
grid on

hL = gridLegend( ax4, 2, {'TS1', 'TS2'} ,'location','southoutside', 'Orientation','Horizontal');

% 4th subplot needs correction of size and position, due to effects of gridLegend 
s3Pos = get(s3,'position');
s4Pos = get(s4,'position');
s4Pos(2:4) = s3Pos(2:4);
set(s4, 'position', s4Pos);

% manipulate the size and position of legend 
newPosition = [0.35 0.0 0.3 0.05];
newUnits = 'normalized';
set(hL,'Position', newPosition,'Units', newUnits);

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

在Matlab中显示带有子图和子图的多个图像

来自分类Dev

在ggplot中绘制带有传说的时间序列的问题(股票价格)

来自分类Dev

带有子图的多个标题(字幕)

来自分类Dev

仅带有ylabel的子图

来自分类Dev

带有子图聚合的递归查询

来自分类Dev

带有子图聚合的递归查询

来自分类Dev

带有多条轨迹的子图

来自分类Dev

绘制子图(Matlab)

来自分类Dev

MATLAB子图使图变大

来自分类Dev

Matlab:图形和子图-如何使Matlab同时放大所有子图?

来自分类Dev

子图如何工作,MATLAB中的子图(121)和子图(1,2,1)有什么区别?

来自分类Dev

子图如何工作,MATLAB中的子图(121)和子图(1,2,1)有什么区别?

来自分类Dev

熊猫图没有传说

来自分类Dev

带有堆叠数据的Python Pandas子图

来自分类Dev

带有子图聚合的递归查询(任意深度)

来自分类Dev

带有堆叠数据的Python Pandas子图

来自分类Dev

带有轴正方形的子图

来自分类Dev

传说的分页

来自分类Dev

传说的分页

来自分类Dev

Matlab更新子图并保持

来自分类Dev

如何对齐MATLAB子图?

来自分类Dev

Matlab:绘图到子图

来自分类Dev

如何绘制带有双 y 轴图的四个子图

来自分类Dev

Graphviz:如何使用带有子图簇的超大图的neato?

来自分类Dev

合并包含子图的Matlab图形

来自分类Dev

Matlab子图显示微小图像

来自分类Dev

MATLAB:一个循环的子图

来自分类Dev

带有子子视图的UIView动画

来自分类Dev

将带有子图的多个图形保存到具有多个页面的pdf中