声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1372|回复: 2

[GUI界面] 平面bar图的一个问题

[复制链接]
发表于 2009-10-18 20:17 | 显示全部楼层 |阅读模式

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

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

x
绘制了三个bar图,代码如下,设置一样,为什么第三个图会和其他两个不一样呢?求达人指教,谢谢

clear
clc
close all
dno=[21 23 405];
endnum=[94 220 440];
data=rand(440,1)*100;
%data=1:440;
map=[0 0.8 0;0.8 0 0;1 1 1];
Hf_fig=figure('position',[0 0 1250 635]);
%作图1——上弦杆%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Ha_1=subplot(2,2,1);
set(Ha_1,'units','pixels');
set(Ha_1,'position',[60 360 endnum(1)*5 250]);
iA1_xuilabel=1;
A1_xuilabel=[];
while iA1_xuilabel<endnum(1)
    A1_xuilabel=[A1_xuilabel iA1_xuilabel];
    iA1_xuilabel=iA1_xuilabel+5;
end
clear iA1_xuilabel
if A1_xuilabel(end)<endnum(1)-2
    A1_xuilabel=[A1_xuilabel endnum(1)];
end
set(Ha_1,'xtick',A1_xuilabel);
data1=data(1:endnum(1));
x1=1:endnum(1);
Hb1_1=bar(x1,data1,'facecolor',[0 0.8 0],'EdgeColor',[1 1 1]);
colormap(map);
set(Hb1_1,'barwidth',1.2)%调整柱状线的宽度
hold on
ddata1=zeros(size(data1,1),size(data1,2));
if ~isempty(dno(find(dno>=1&dno<=endnum(1))))
    x1_dno=dno(find(dno>=1&dno<=endnum(1)));
    ddata1=zeros(size(data1,1),size(data1,2));
    for ix1_dno=1:length(x1_dno)
        ddata1(x1_dno(ix1_dno))=data(x1_dno(ix1_dno));
    end
    clear ix1_dno
end
Hb1_2=bar(x1,ddata1,'facecolor',[0.8 0 0],'EdgeColor',[1 1 1]);
set(Hb1_2,'barwidth',1.2)%调整柱状线的宽度
hold off
Hl1=legend('无损伤杆件','损伤杆件');
set(Ha_1,'box','off');
set(Ha_1,'TickLength',[0 0]);
set(Ha_1,'ygrid','on');
set(get(Ha_1,'title'),'string','上弦杆损伤程度','fontweight','bold','fontsize',12,'units','pixels');
set(get(Ha_1,'title'),'position',[230 254 0]);
set(get(Ha_1,'ylabel'),'string','差异百分比','units','pixels','position',[-25 125 0],'rotation',90);
set(get(Ha_1,'xlabel'),'string','杆件编号');
set(Ha_1,'xlim',[0 endnum(1)+1]);
%作图2——下弦杆%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Ha_2=subplot(2,2,2);
set(Ha_2,'units','pixels');
set(Ha_2,'position',[115+endnum(1)*5 360 (endnum(2)-endnum(1)+1)*5 250]);%算法有问题需要调整
iA2_xuitick=1+endnum(1);
A2_xuitick=[];
while iA2_xuitick<endnum(2)&&iA2_xuitick>endnum(1)
    A2_xuitick=[A2_xuitick iA2_xuitick];
    iA2_xuitick=iA2_xuitick+5;%每隔5个数生成一个x坐标标记
end
clear iA2_xuitick
if A2_xuitick(end)<endnum(2)-2
    A2_xuitick=[A2_xuitick endnum(2)];
end
data2=data(1+endnum(1):endnum(2));
x2=1+endnum(1):endnum(2);
Hb2_1=bar(x2,data2,'facecolor',[0 0.8 0],'EdgeColor',[1 1 1]);
colormap(map);
set(Hb2_1,'barwidth',1.2)%调整柱状线的宽度
hold on
ddata2=zeros(size(data2,1),size(data2,2));
if ~isempty(dno(find(dno>=1+endnum(1)&dno<=endnum(2))))
    x2_dno=dno(find(dno>=1+endnum(1)&dno<=endnum(2)));
   
     for ix2_dno=1:length(x2_dno)
        ddata2(x2_dno(ix2_dno)-endnum(1))=data(x2_dno(ix2_dno));
    end
end
Hb2_2=bar(x2,ddata2,'facecolor',[0.8 0 0],'EdgeColor',[1 1 1]);
set(Hb2_2,'barwidth',1.2)%调整柱状线的宽度
hold off
Hl2=legend('无损伤杆件','损伤杆件');
set(Ha_2,'xtick',A2_xuitick);
set(Ha_2,'xticklabel',A2_xuitick);
set(Ha_2,'box','off');
set(Ha_2,'TickLength',[0 0]);
set(Ha_2,'ygrid','on');
set(get(Ha_2,'title'),'string','下弦杆损伤程度','fontweight','bold','fontsize',12,'units','pixels');
set(get(Ha_2,'title'),'position',[325 254 0]);
set(get(Ha_2,'ylabel'),'string','差异百分比','units','pixels','position',[-25 125 0],'rotation',90);
set(get(Ha_2,'xlabel'),'string','杆件编号');
set(Ha_2,'xlim',[endnum(1) endnum(2)+1]);
%作图3——腹杆%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Ha_3=subplot(2,2,[3 4]);
set(Ha_3,'units','pixels');
set(Ha_3,'position',[95 45 (endnum(3)-endnum(2)+1)*5 250]);%左60像素,高25像素,长度由数据量觉得,框高250
iA3_xuitick=1+endnum(2);
A3_xuitick=[];
while iA3_xuitick<endnum(3)&&iA3_xuitick>endnum(2)
    A3_xuitick=[A3_xuitick iA3_xuitick];
    iA3_xuitick=iA3_xuitick+5;%每隔5个数生成一个x坐标标记
end
clear iA3_xuitick
if A3_xuitick(end)<endnum(3)-2
    A3_xuitick=[A3_xuitick endnum(3)];
end
data3=data(1+endnum(2):endnum(3));
x3=1+endnum(2):endnum(3);
Hb3_1=bar(x3,data3,'facecolor',[0 0.8 0],'EdgeColor',[1 1 1]);
colormap(map);
set(Hb3_1,'barwidth',1.0)%调整柱状线的宽度
hold on
ddata3=zeros(size(data3,1),size(data3,2));
if ~isempty(dno(find(dno>=1+endnum(2)&dno<=endnum(3))))
    x3_dno=dno(find(dno>=1+endnum(2)&dno<=endnum(3)));
   
    for ix3_dno=1:length(x3_dno)
        ddata3(x3_dno(ix3_dno)-endnum(2))=data(x3_dno(ix3_dno));
    end
end
Hb3_2=bar(x3,ddata3,'facecolor',[0.8 0 0],'EdgeColor',[1 1 1]);
set(Hb3_2,'barwidth',1.0)%调整柱状线的宽度
hold off
Hl3=legend('无损伤杆件','损伤杆件');
set(Ha_3,'xtick',A3_xuitick);
set(Ha_3,'xticklabel',A3_xuitick);
set(Ha_3,'box','off');
set(Ha_3,'TickLength',[0 0]);
set(Ha_3,'ygrid','on');
set(get(Ha_3,'title'),'string','腹杆损伤程度','fontweight','bold','fontsize',12,'units','pixels');
set(get(Ha_3,'title'),'position',[550 254 0]);
set(get(Ha_3,'ylabel'),'string','差异百分比','units','pixels','position',[-25 125 0],'rotation',90);
set(get(Ha_3,'xlabel'),'string','杆件编号');
set(Ha_3,'xlim',[endnum(2) endnum(3)+1]);

untitled.fig

53.9 KB, 下载次数: 2

回复
分享到:

使用道具 举报

发表于 2009-10-19 00:26 | 显示全部楼层
不清楚什么不一样?
 楼主| 发表于 2009-10-19 09:45 | 显示全部楼层
附件的fig文件里面是图,后来发现是第三个图的edgecolor的设置没有成功(Hb3_1=bar(x3,data3,'facecolor',[0 0.8 0],'EdgeColor',[1 1 1]);)。重新用set(Hb3_1,'EdgeColor',[1 1 1]),就改过来了,谢谢Happy

评分

1

查看全部评分

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

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

GMT+8, 2024-12-30 02:11 , Processed in 0.100282 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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