assign differernt marker and put an offset in x-axis in subplot()

4 ビュー (過去 30 日間)
Hassan
Hassan 2011 年 5 月 5 日
I have an array y(15 rows, 80 columns) and x(1,80) and want to plot each row of y against x.
I wonder how I can assign differernt marker to each plot. there are 15 rows in array y so I need 15 different markers.
I also wonder how I can put an offset in x-axis since the markers for the first x and y falls on y axis.
I would be grateful for your help.
x=1:80;
y=rand(15,80);
j=1;
for i=1:16
subplot(6,3,i),plot(x(j:j+4),y(:,j:j+4),'LineStyle','none','Marker'
,'+')
j=j+5;
end

採用された回答

Teja Muppirala
Teja Muppirala 2011 年 5 月 5 日
You have 15 different patterns, and since there are only 13 possible markers, why not divide them up using (5 markers) x (3 colors)?
x=1:80;
y=rand(15,80);
j=1;
%5 different markers, 3 different colors
markerlist = {'+' 'x' 'o' 's' 'd'};
colorlist = {'r' 'k' [.5 .5 1]};
for i=1:16
subplot(6,3,i)
hold on;
row = 0;
for kk = 1:3
for jj = 1:5
row = row+1;
plot(x(j:j+4),y(row,j:j+4),'LineStyle','none','Marker',...
markerlist{jj},'color',colorlist{kk})
end
end
j=j+5;
%Add offset
xlim(xlim + [-0.5 0.5]);
end
  2 件のコメント
Hassan
Hassan 2011 年 5 月 5 日
thanks a lot Teja for the help.
Hassan
Hassan 2011 年 5 月 5 日
about the offset in x-axis, for the even subplots it is fine for the odd subplots there's an extra x label. Is it possible to remove those extra x labels?

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

その他の回答 (1 件)

Jarrod Rivituso
Jarrod Rivituso 2011 年 5 月 5 日
Two comments
  • You can easily plot a group of lines using a single call to the plot function if you arrange each column of the y matrix to be a separate line plot's data (so, make it 80-by-15 instead of 15-by-80)
  • You can get a list of all available markers (there are 13 of them) from the set function
Here's an example
x = (1:80)';
y = rand(80,15);
plotHandles = plot(x,y,'Linestyle','none');
markerNames = set(plotHandles(1),'Marker');
for i = 1:length(plotHandles)
markerIndex = mod(i,13)+1
set(plotHandles(i),'Marker',markerNames{markerIndex});
end
  4 件のコメント
Jarrod Rivituso
Jarrod Rivituso 2011 年 5 月 5 日
oops, i read it quickly. good point Teja :)
Hassan
Hassan 2011 年 5 月 5 日
thanks Jarrod for the help. I learnt some good points from your code.

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by