Matlab画图,x轴标注变倾斜

摘要:matlab画图时,x轴坐标太多,想倾斜放置。代码记录如下:


一、直接上代码

1.代码

代码如下(示例):

%准备数据
Y=[0.7482    0.7981    0.7436
    0.7575    0.7931    0.7183
    0.9291    0.9291    0.8826
    0.8117    0.8120    0.8826
    0.8661    0.8661    0.7753
    0.8783    0.8804    0.7153
    0.7177    0.6670    0.8032
    0.8718    0.8720    0.6063
    0.7000    0.8565    0.5892
    0.8000    0.8979    0.8426
    0.6000    0.5228    0.6480
    0.8000    0.8215    0.6956
    0.8073    0.7320    0.7555
    0.7702    0.7702    0.6631
    0.8066    0.8066    0.7318
    0.6503    0.7732    0.7571];
X=1:16;
 %画出4组柱状图,宽度1
h=bar(X,Y,1);    
 %修改横坐标名称、字体
Cell = {'Arts','Birds','Business','CAL500','Computers','Corel5k','Education','Emotions','Eron','Health','Image','Rcv1','Scene','Slashdot','Society','Yeast'};
set(gca, 'XTick',1:16, 'XTickLabel',Cell);
set(gca,'XTickLabel',{'Arts','Birds','Business','CAL500','Computers','Corel5k','Education','Emotions','Eron','Health','Image','Rcv1','Scene','Slashdot','Society','Yeast'},'FontSize',10,'FontName','Times New Roman');
set(gca,'XTickLabelRotation',46);%46是字体的旋转角度
set(gca,'XLim',[0 numel(Cell)+1]);

% 设置柱子颜色,颜色为RGB三原色,每个值在0~1之间即可
set(h(1),'FaceColor',[30,150,252]/255)     
set(h(2),'FaceColor',[162,214,249]/255)    
set(h(3),'FaceColor',[252,243,0]/255)    
%set(h(4),'FaceColor',[255,198,0]/255)    
ylim([0,1]);      %y轴刻度
%修改x,y轴标签
ylabel('\fontname{Times New Roman}\fontsize{14}AUC');
xlabel('\fontsize{14}Data sets'); 
%修改图例
legend({'\fontname{Times New Roman}CS2PML','\fontname{Times New Roman}CS2PML-n','\fontname{Times New Roman}CS2PML-d'},'FontSize',10);

起作用的部分是下面这块:

set(gca, 'XTick',1:16, 'XTickLabel',Cell);
set(gca,'XTickLabel',{'Arts','Birds','Business','CAL500','Computers','Corel5k','Education','Emotions','Eron','Health','Image','Rcv1','Scene','Slashdot','Society','Yeast'},'FontSize',10,'FontName','Times New Roman');
set(gca,'XTickLabelRotation',46);%46是字体的旋转角度
set(gca,'XLim',[0 numel(Cell)+1]);

2.效果如图

在这里插入图片描述

  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值