Scaling pcolor graphics on subplots

5 次查看(过去 30 天)
I'm trying to subplot (by collumns) a bar, a pcolor, 8 pcolors, one plot. Problem is: the matrixes for the 8 pcolors are being plotted way to small. I'd like to make them bigger, filling the whole "cell" of the subplot (I'm getting something like I tenth of it!).
My code goes something like this:
cmap = [1 0 0;0.5,0.5,0.5;0,0,1];
A = ones(1,10) * 5;
B = zeros(50);
for a = 1:10
diagonal = [ones(1,a-1) zeros(1,10-a+1)];
C{a} = diag(diagonal, 0);
end
D_base = [10 10 9 8 7 5 3 2 1 0];
for a = 1:10
D{a} = D_base + rand(1,10);
end
% Plotting functions
x = [1 2 9 10 17 18 25 26];
%%First block plotting
subplot(4,8,[1 26]), bar(A)
xlim([0.3 10.8])
ylim([0 13])
xlabel('Group')
ylabel('Species')
%%Second block plotting
y = [x(1)+2 x(8)+2]; %Defining positions
h = subplot(4,8,y), pcolor(B) ;
xlim([1 length(B)]); % Limits X-axis
ylim([1 length(B)]); % Limits Y-axis
axis off;
colormap(cmap);
caxis([-1 1])
axis ij;
title(B)
set(get(gca, 'Title'), 'Color', [0.166 0 0]);
%%Third block plot
x = x + 4; %Defining positions
for a = 1:8 % I know I'm not plotting the whole thing
h = subplot(4,8,x(a)), pcolor(C{a}) ;
xlim([1 length(B)]);
ylim([1 length(B)]);
axis off;
colormap(cmap);
caxis([-1 1])
axis ij;
title(a)
set(get(gca, 'Title'), 'Color', [a*0.1 0 0]);
end
%%Fourth block plotting
x = [7 32]; % Defining positions
% Collor defining
cmap = zeros(8,3);
cmap(1) = 0.3;
aux = [0.1 0 0];
%ploting
for a = 2:8
cmap(a,:) = cmap(a-1,:) + aux;
end
for a = 1:8
subplot(4,8,x), plot(D{a},'Color',cmap(a,:))
hold on
end
Any ideas on how to make the C subplots larger?

采纳的回答

Fangjun Jiang
Fangjun Jiang 2011-10-16
If you comment out the following two lines in the "Third block plot". The figure is about right.
xlim([1 length(B)]);
ylim([1 length(B)]);
  1 个评论
Igor de Britto
Igor de Britto 2011-10-17
Thanks a lot. I did the same mistake on the original code (setting limits with the wrong variables!)

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2011-10-16
Try adjusting the Position or OuterPosition property of the plot just after you call pcolor. I'd also like you to explain why you're using pcolor at all, instead of image(), because I don't like the fact that each tile doesn't represent one pixel and you have one less little tile across than you have pixels across.
  2 个评论
Igor de Britto
Igor de Britto 2011-10-17
Thanks for the reply. I'm using pcolor because it was the method previously suggested - xxx - that happened to work just fine. I did have a few problems with my instalation and it didn't allow me to use the caxis command on a few plots (imagesc, for instance). I know it's annoying to add a few empty lines (and yes, I did forget putting them on this pcolor plot!), but I guess I'm going by inertial movement. Do you know if the above code would work properly with image and grid on?
Image Analyst
Image Analyst 2011-10-17
Well I'd suggest not using pcolor() and using image() instead, the main problem being that the color of each tile in pcolor is not directly related to the value of the pixel.
Getting the right position settings for each plot will be tedious so I'll leave that to you. The images will be pretty tiny though so I wonder how useful they'll be. If it were me I'd create another figure for your array of images so they'll be big enough to actually see.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Blue 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by