带有多个标记的散点图

时间:2013-01-08 04:20:44

标签: matlab markers scatter-plot

我试图将散点图放在一起来自多个数据文件,以查看彼此之间的关联方式。代码如下所示:

hold all
fia = fopen('data.txt');
A = fscanf(fia, '%f %f %f', [3 inf]);
t = A(1,:);
a = A(2,:);
r = A(3,:);

figure(1)
scatter(log(r),log(a),'r', '-');

fclose(fia);

fia = fopen('data.txt');
A = fscanf(fia, '%f %f %f', [3 inf]);
t = A(1,:);
a = A(2,:);
r = A(3,:);

figure(2);
scatter(log(r),log(a), 'g', '-');

fclose(fia);

依此类推,下一个数据点绘制在同一图表上:

fia = fopen('data.txt');
A = fscanf(fia, '%f %f %f', [3 inf]);
t = A(1,:);
a = A(2,:);
r = A(3,:);

figure(1);
scatter(log(r),log(a), 'rx');


fclose(fia);

等。

但是当我在Matlab中运行该函数时,我收到了这个错误:

Error using specgraph.scattergroup/set
The name 'linestyle' is not an accessible property for an instance
of class 'scattergroup'.

Error in specgraph.scattergroup (line 26)
  set(h,args{:});

Error in scatter (line 83)
        h = specgraph.scattergroup('parent',parax,'cdata',c,...

Error in Ratioincrease (line 11)
scatter(log(r),log(a),'r', '-');

如何将散点组与线组相似,如何正确编写?

3 个答案:

答案 0 :(得分:6)

使用scatter并显示不同的标记应该没有问题。例如:

load seamount
scatter(x,y,30,z,'s'); hold on
scatter(.999*x,1.001*y,30,z,'x'); hold on
scatter(1.001*x,.999*y,30,z,'+'); hold on

enter image description here

我怀疑你输错了,并使用-作为标记类型。您可以使用的标记类型是:

  • '+'加号
  • 'o'
  • '*' Asterisk
  • '.'
  • 'x' Cross
  • 'square''s' Square
  • 'diamond''d' Diamond
  • '^'向上指向的三角形
  • 'v'向下指向的三角形
  • '>'右指三角
  • '<'左指三角
  • 'pentagram''p'五角星(五角星)
  • 'hexagram''h'六角星(六芒星)

答案 1 :(得分:1)

只是要补充一点,你不必为每一行写'hold on'。一次就足够了。 所以,为此你可以写:

load seamount
scatter(x,y,30,z,'s'); hold on
scatter(.999*x,1.001*y,30,z,'x'); 
scatter(1.001*x,.999*y,30,z,'+'); 

另外,如果你想绘制一组新的数据并清理前一个数据,你需要在执行此命令之前写一次“hold off”。

答案 2 :(得分:-2)

分散群组属性名称是&#39;标记&#39;

签入doc&#39; Scattergroup Properties&#39;