【原创】Matlab 设置Colorbar字体,导出时字体颜色改变-解决方案
2015-09-02 06:43阅读:
具体原因不详,解决方法是:
1。关闭默认的axis label; (axis off)
2. 单独设置coloarbar, 包括字体大小等;
3。单独设置 xlabel 和ylabel.
4. 导出时要勾选 'customize font size' (and image resolution setting as
necessary).
详细的请参加以下代码中的 Method 2.
%***********************************************************************
close all
clear
clc
%%
***********************************************************************
S1 = load('S1_DAS_Time_Delay_Ant_1.mat');
S1 = load('S1_DAS_Time_Delay_Ant_4.mat');
S1 = load('S1_DAS_Time_Delay_Ant_8.mat');
S1 = load('S1_DAS_Time_Delay_Ant_12.mat');
S1 = load('S1_DAS_Time_Delay_Ant_16.mat');
S1 = load('S1_DAS_Time_Delay_Ant_20.mat');
BP1 = struct2cell(S1);
data = cell2mat(BP1);
basistimeslot = 1.91e-12;
data = data*basistimeslot;
imagesc(data);
%{
%**************************************************************Method
1 -[workable but not perfect - coloar text export disappear]
myfontsize = 35;
mytitlefontsize = 35;
r> my_colorbar_fontsize = 30;%(1-5)
colorbar;
myfontname = 'Times New Roman';
I = colorbar;%Correct solution
%set(I,'FontWeight', 'Normal', 'Color',
'k','FontSize',my_colorbar_fontsize,'FontName',myfontname);
set(I,'FontWeight', 'Normal',
'FontSize',my_colorbar_fontsize,'FontName',myfontname);
colormap(hot);%hot colormap, suitable for both black-white print,
and color-print and online browsing (More details than grey scale,
and suitable for b/w print);
axis equal;
%xlabel('pixel #');
%ylabel('pixel #');
[imagerow,imagecol] = size(data);
axis ([1 imagecol 1 imagerow]);
myfontname = 'Times New Roman';
set(gca,'FontWeight', 'Normal', 'Color',
'k','FontSize',mytitlefontsize,'FontName',myfontname);%set actual
content for display
textstr={'pixel #'};
text(43,140, textstr, 'FontWeight', 'Normal', 'Color',
'k','FontSize',mytitlefontsize,'FontName',myfontname);
text(-20,70, textstr, 'FontWeight', 'Normal', 'Color',
'k','FontSize',mytitlefontsize,'FontName',myfontname);
%}
%****[Method 2 - Perfect - Added color bar and x&y label -
export colorbar looks perfect - 01 Sep 2015 (after viva)]****
%-
colormap(hot);
axis equal;
[imagerow,imagecol] = size(data);
axis ([1 imagecol 1 imagerow]);
myfontsize = 42;
mytitlefontsize = 42;
my_colorbar_fontsize = 41;%(1-5)
myfontname = 'Times New Roman';
% myfontname = 'Helvetica';
I = colorbar;%Correct solution
set(I,'FontWeight', 'Normal', 'Color',
'k','FontSize',my_colorbar_fontsize,'FontName',myfontname)
axis off;
xrange = xlim;xmin = xrange (1,1);xmax = xrange (1,2);
yrange = ylim;ymin = yrange (1,1);ymax = yrange (1,2);
%*****************************[X
axis]*****************************
myshowxa = char('50','100');%The content want to present - char
format;
myshowx_num = [50,100];%The content want to present -num
format;
actual_start = 0;%This is the actual x start of the model;
x_ori_max = 100;%This is the actual x end of the model;
xanew = [xmax*(myshowx_num(1,1) -
actual_start)/x_ori_max,xmax*(myshowx_num(1,2)-actual_start)/x_ori_max];E
is the starting point position;
xanew = xanew - 7;%Minus 80 for move the label to an appropriate
position;
myxa = num2str(xanew);
ym = get(gca, 'YLim');
ya = repmat(ym(2), 1, length(xanew));
hold on;text(str2num(myxa), ya + 7, num2str(myshowxa),'FontWeight',
'Normal', 'Color',
'k','FontSize',myfontsize,'FontName',myfontname);
%***********[x axis - Title]***********
titlex = 0.34*xmax;
titley = ym(2) + 270;
textstr={'pixel #'};
h = text(42,142, textstr, 'FontWeight', 'Normal', 'Color',
'k','FontSize',mytitlefontsize,'FontName',myfontname);
%set(h,'Rotation',90); �n adjust the font direction-horizontal or
vertical;
%*****************************[Y
axis]*****************************
myshowxa = char('20','40','60','80','100','120');%The content want
to present-char;
myshowx_num = [20,40,60,80,100,120];%The content want to
present-num;
x_ori_max = 130;
xmax = ymax;%This time, for yaxis
% xanew =
[xmax*(myshowx_num(1,1)-actual_start)/x_ori_max,xmax*(myshowx_num(1,2)-actual_start)/x_ori_max,xmax*(myshowx_num(1,3)-actual_start)/x_ori_max,xmax*(myshowx_num(1,4)-actual_start)/x_ori_max,xmax*(myshowx_num(1,5)-actual_start)/x_ori_max];E
is the starting point position;
xanew =
[xmax*(myshowx_num(1,1))/x_ori_max,xmax*(myshowx_num(1,2))/x_ori_max,xmax*(myshowx_num(1,3))/x_ori_max,xmax*(myshowx_num(1,4))/x_ori_max,xmax*(myshowx_num(1,5))/x_ori_max,xmax*(myshowx_num(1,6))/x_ori_max];E
is the starting point position;
%xanew = xanew - 1110;
myxa = num2str(xanew);
ym = get(gca, 'XLim');
ya = [-300,-300,-300,-300,-303,-303];�just the character
position;
ya = ya + 290;
hold on;text(ya, str2num(myxa),num2str(myshowxa),'FontWeight',
'Normal', 'Color',
'k','FontSize',myfontsize,'FontName',myfontname);
%***********[Y axis - Title]***********
titlex = xmin - 520;
titley = 0.6*ymax + 125;
textstr={'pixel #'};
h = text(-12,70, textstr, 'FontWeight', 'Normal', 'Color',
'k','FontSize',mytitlefontsize,'FontName',myfontname);set(h,'Rotation',90);
%*****************************[END]*****************************
a=1
%***********************************************************************