Move subplot title and create colored line beside it.

1 回表示 (過去 30 日間)
Igor de Britto
Igor de Britto 2012 年 3 月 5 日
Hi, all. I have this plot code for visualizing the matrices that originate a curve being ploted. Each matrix is subploted with a title and has it's curve ploted on a same area for all of the curves. Title and curve share the same color (first matrix is red, so it's curve is also red and so on).
However, I'd like to do two things with it:
  1. Move the title of each matrix to the left upper corner of it.
  2. Create a line along the rest of the subplot square with the same color as the title.
Any ideas?
Here goes my code, with adaptations for not needing to load results form actual previous computations.
clear
clc
for a = 1:4
acumuladorSIS{4,5,a,1,2} = ceil(rand(50)*3)-2;
acumulador2{4,5,a,1,2} = ceil(rand(1,50)*10);
end
acumulador3{1,1} = ceil(rand(1,50)*10);
QSG = 50;
figure
cmapInt = [1, 0, 0; 1, 1, 1; 0, 0, 1];
cmapPlot = [
1 0 0
0 0.7 0
0 0 0.9
0.5 0.5 0.5];
aMax = 4;
b = 1; % aleatorização; 1 = não; 2 = sim;
c = 2; % sinal. 1 = +; 2 = -
d = 4; % distribuição de espécies nos grupos
e = 5; % tipo de distribuição de sinais entre espécies
%%matrizes de interação
pos = [1 5 9 13]
for a = 1:aMax
subplot(4,4,pos(a)),...
imagesc(acumuladorSIS{d,e,a,b,c})
colormap(cmapInt)
caxis([-1 1])
xlim([1 sum(QSG)])
ylim([1 sum(QSG)])
title(a)
set(get(gca, 'Title'), 'Color', cmapPlot(a,:));
end
%%curvas de perda de diversidade funcional
for a = 1:4
hold on
subplot(4,4,[2 16]), ...
plot(acumulador2{d,e,a,b,c}),...
'Color', cmapPlot(a,:)
% to-do: ajeitar cores e tipos de linhas
box off
end
hold on
subplot(4,4,[2 16]), ...
plot(acumulador3{1,1}, '--black')
box off
  1 件のコメント
Igor de Britto
Igor de Britto 2012 年 3 月 5 日
Sorry, there's a typo on the final plots. The parenthesis show should appear after the cmap statement.
subplot(4,4,[2 16]), ...
plot(acumulador2{d,e,a,b,c} --->)<---,...
'Color', cmapPlot(a,:)

サインインしてコメントする。

回答 (1 件)

Geoff
Geoff 2012 年 3 月 5 日
I don't know how to answer your 'line' question, but to set the title position do this:
h = get(gca, 'Title');
set(h, 'Units', 'normalized');
set(h, 'Position', [0,1,0]);
set(h, 'HorizontalAlignment', 'left');
set(h, 'VerticalAlignment', 'bottom');
Play around with those position and alignment values to put the test where you want it, whether that's inside or outside the axes etc.
If your line is simply to separate graphs (so titles don't collide with the other plots), then you may want to consider putting the title inside the axis area. You can make it stand out by modifying the FontWeight and FontSize properties.
-g-
  1 件のコメント
Igor de Britto
Igor de Britto 2012 年 3 月 6 日
Thanks a lot on the title position tip, Geoff. It worked like a charm. The point of the line, however, is to make it easier to identify wich line was generated (the same idea behind linking title color and line plot color), because it will be more visible on a small picture than the number.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTitle についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by