声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 6265|回复: 14

[编程技巧] 画图问题,点过多,用星号画图,结果成了粗线。

[复制链接]
发表于 2009-6-7 19:16 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
Rt
图中的星号都连到一起,成了粗实线。
untitled.jpg
回复
分享到:

使用道具 举报

发表于 2009-6-7 21:23 | 显示全部楼层
点太密了,可以让间隔大一些

评分

1

查看全部评分

发表于 2009-6-7 22:58 | 显示全部楼层
应该也可以把星号弄小点。。。

评分

1

查看全部评分

发表于 2009-6-8 10:39 | 显示全部楼层
放大以后可以看出各个点
 楼主| 发表于 2009-6-8 12:22 | 显示全部楼层

回复 沙发 friendchj 的帖子

我当然知道点太密了,我也知道seeksun说的什么放大一点。。。。
我就想看看你们有没有什么建设性建议。

回复 板凳 dtczhl 的帖子
把星号弄小?
你的想法很独特,给点可以实现的简例。

[ 本帖最后由 ChaChing 于 2010-8-10 15:15 编辑 ]
发表于 2009-6-8 15:36 | 显示全部楼层

我原先试图较小符号,发现效果不明显,太小的话,*号和点看起来一样,所以才建议减少点数。试比较:
clc; clear
x=1:0.05:5; y=1:length(x);
subplot(221); plot(y,x,'*'); title('正常')
subplot(222); plot(y(1:4:end),x(1:4:end),'*'); title('减少点')
subplot(223); plot(y,x,'*','MarkerSize',4); title('减小符号,默认为6')
subplot(224); plot(y,x,'*','MarkerSize',1); title('减小符号,默认为6')

[ 本帖最后由 ChaChing 于 2010-8-10 15:14 编辑 ]
untitled.jpg

评分

1

查看全部评分

发表于 2009-6-8 15:52 | 显示全部楼层
 楼主| 发表于 2009-6-8 16:56 | 显示全部楼层

回复 8楼 ChaChing 的帖子

我说ChaChing,你很高明啊,每次都到点子上,这个网站是怎么回事?
有人自己开发的Matlab程序?
顺便把调用格式也写出来吧。

  1. x=-1:0.01:1;
  2. y=sin(x);
  3. xx=plot(x,y)
  4. addmarkers(xx,10)
复制代码

评分

1

查看全部评分

 楼主| 发表于 2009-6-8 17:02 | 显示全部楼层

回复 7楼 friendchj 的帖子

其实我自己写了一个和ChaChing说的那个功能差不多的函数。

  1. function plotnew(p,x,y1)
  2. clear xx
  3. clear yy1
  4. L=length(x);
  5. %p:控制符号的密度;
  6. %s=round(L/p-1);%p如果取太大,那么就会造成比较明显的误差,一般50以内可以。
  7. for j=1:p;
  8.         i=round((j-1)*L/p)+1;
  9.         xx(j)=x(i);
  10.         yy1(j)=y1(i);
  11.         %yy2(j)=y2(i);
  12.         %yy3(j)=y3(i);
  13. end
  14. hh=plot(x,y1,'b',xx,yy1,'*');
  15. legend(hh(2),'哈哈');
复制代码

评分

1

查看全部评分

发表于 2009-6-8 19:20 | 显示全部楼层

回复 10楼 beyondhxf 的帖子

画好曲线后, 将曲线的数据按一定间隔抽取出来再画没有线型的星号
参考
xv=1:0.1:10;
yv=sin(xv);
plot(xv,yv);
hold on
plot(xv(1:10:end),yv(1:10:end),'*','linestyle','none');

MATLAB就有这个麻烦,很多年了也不解决这个问题
 楼主| 发表于 2009-6-8 20:11 | 显示全部楼层

回复 11楼 VibrationMaster 的帖子

到目前为止,都是在原有的直线上覆盖星号。
同样的原理。
发表于 2010-7-22 16:51 | 显示全部楼层
楼上的方法想的挺好,但是问题又来了,在你添加Legend时会发现多了几个无用的标识……
发表于 2010-7-22 23:47 | 显示全部楼层

回复 13楼 Sunvisual 的帖子

好问题! 但应该不难解决
请搜一下应可找到答案
发表于 2012-5-24 14:37 | 显示全部楼层
本帖最后由 cjfunsw 于 2012-5-24 14:41 编辑

回复 7 # ChaChing 的帖子

ChaChing,你好,我也想用你提供的这个说明。但是我尽管看了Beyondhxf的例子,我还是用不了。请问能提供一个详细的例子,应用这个功能的吗?

或者其他朋友用过这个功能的,能否提供下详细的例子。我是把这个funtion放在m文件开头,然后就从excel里读取数据,再plot图片。然后用addmarkers()的功能。但是总是提示说错误。因为那个narin<1所以出现错误,是怎么回事呢。

我是这么用的,请问哪里错了。

functionho=addmarkers(hi,n)
% ADDMARKERS    Add a pre-defined number of markers to a plot instead of

% one at each datapoint which is default in Matlab.

%

% Usage:

% ADDMARKERS(HI) adds 5 markers to the input handle HI, J=1..length(HI)

% ADDMARKERS(HI,N) adds N markers to the input handle HI, J=1..length(HI)

% HO=ADDMARKERS(...) returns the output handle HO for future usage such as

% changing colors, markers, etc.

%

% Hint: use the output handle when adding legends, e.g.

% LEGEND(HO,'legend 1',...,'legend N')

%

% The markers will be added in the following order:

%

% o     Circle

% s     Square

% d     Diamond

% x     Cross

% +     Plus sign

% *     Asterisk

% .     Point

% ^     Upward-pointing triangle

% v     Downward-pointing triangle

% >     Right-pointing triangle

% <     Left-pointing triangle

% p     Five-pointed star (pentagram)

% h     Six-pointed start (hexagram)

%

% By Matthijs Klomp at Saab Automobile AB, 2009-10-11

% E-mail: matthijs.klomp@gm.com

%

if


nargin<2, n=5; end % default number of markers

if


nargin<1, error('Supply an input handle as input argument.'), end

figure(get(get(hi(1),

'parent'),'parent'))% plot in the figure of the handle

subplot(get(hi(1),

'parent'))            % plot in the subplot of the handle

hold

on                                 % do not overwrite the current plot

markers = {

'o','s','d','^','v','x','+','*','.','>','<','p','h'};

ho = hi;                                

% initialize output handle

for


i = 1:length(hi)

    x = get(hi(i),

'xdata');             % get the independent variable

    y = get(hi(i),

'ydata');             % get the dependent variable data

    s = linspace(1,n,length(x));        

% sampling independent variable

    sn = [1 (2:n-1)+randn(1,n-2)/n n];  

% add some noise to avoid overlap

    xrs = interp1(s,x,sn,

'nearest');    % downsample to n datapoints

    yrs = interp1(s,y,sn,

'nearest');    % downsample to n datapoints

    plot(xrs,yrs,

...                    % Plot the markers



'Marker',markers{i},'LineStyle','None','Color',get(hi(i),'Color'));

    ho(i) = plot([0 1],[1 1]*NaN,

...    % Create the output handle



'Marker',markers{i},...



'LineStyle',get(hi(i),'Linestyle'),...



'Color',get(hi(i),'Color'));

end

if


nargout==0, clear ho, end



A=xlsread(

'C:\D10RMethod1.xlsx','sheet2','a3:j1953');

x2=plot(A(:,1),A(:,2))

ho=addmarkers(x2,10)


谢谢。
发表于 2012-5-25 01:29 | 显示全部楼层
回复 14 # cjfunsw 的帖子

搜索下, 先学下函数的使用!
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-21 05:37 , Processed in 0.078373 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表