摘要: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]);