MATLAB Answers

Exported figure size is huge and specified font of the label is ignored in 2014b

10 views (last 30 days)
Wonjun Choi
Wonjun Choi on 24 Nov 2014
Answered: Rob Comer on 5 Jun 2015
Hello.
I updated MATLAB to 2014b last week. After update, I found some problems regarding figure in 2014b, but don't how to solve it.
  1. Specified label font doesn't work in 2014b. I specified label font as "Times New Roman", but it looks like "Arial". It works in 2014a, but not in 2014b.
  2. Exported figure size is extremely huge. When I export the figure as emf or eps using "print", the size of figure file is about 200 MB. It was about 500 kb when I ran the code in 2014a.
After I found out something wrong in 2014b, I ran my code in 2014a again, but it works well. I don't know how to solve the problems. Would you give me an advice?
%%X-Z 2D contour script
% Raw data Columns 1=ID, 2=X, 3=Y, 4=Z, 5=NODE, 6=SLICE, 7=HINIT, 8=Time
clc;clear;
close all; %close figures
format bank
%%1-1 Excel data read
% RawData=xlsread('AllnodesTemp_Load1_Tokyo_30day_2yr');
%%1-2 DAT file read
% Raw data Columns 1=ID, 2=X, 3=Y, 4=Z, 5=NODE, 6=SLICE, 7=HINIT, 8=Time
fid = fopen('AllNodeTemp_20yr_365d.dat', 'r'); %read the data (txt,csv,dat,dlm,tab,asc)
EndOfHeader=1; %Number of Header line
for i=1:EndOfHeader
buffer = fgetl(fid); %fgetln : skip the header line one by one.
end
Data = textscan(fid,'%f %f %f %f %f %f %f %f'); %read the data
%Assign the data of each column
% c1 = Data{1}; c2 = Data{2}; c3 = Data{3};
RawData=[Data{:}];
clearvars -except RawData; %Delete all the variables except followings
%%Contour Setting
rb=0.0825; %radius of borehole
T_ini=17; %initial temperature
% Y coordinate to cut the slice (Filter y-coordinate)
Ycoord1 = 0;
Ycoord2 = 7.5;
Ycoord3 = -7.5;
%%Figure Data Generation
%Filter data for certain slice
n=1; %n must be out of for loop
for i=1:size(RawData,1); %Row number of RawData1
if RawData(i,3)==Ycoord1; %Filter based on the Z coordinates (Depth)
GridData1(n,1:3)=RawData(i,[2,4,7]); %Correct z0
n=n+1;
end
end
% Filter cetain slice is done.
GridDataX1=GridData1(:,1); % X-coordinates
GridDataZ1=GridData1(:,2); % Y-coordinates
GridDataT1=GridData1(:,3); %Temp values
MaxT1 = ceil(max(GridDataT1)); MinT1 = floor(min(GridDataT1)); %min and max display
%Filter data for certain slice
%Figure (b)
n=1; %n must be out of for loop
for i=1:size(RawData,1); %
if RawData(i,3)==Ycoord2; %
GridData2(n,1:3)=RawData(i,[2,4,7]); %C
n=n+1;
end
end
% Filter cetain slice is done.
GridDataX2=GridData2(:,1); % X-coordinates
GridDataZ2=GridData2(:,2); % Y-coordinates
GridDataT2=GridData2(:,3); %Temp values
MaxT2=ceil(max(GridDataT2)); MinT2=floor(min(GridDataT2));
% X=unique(g_data_x)'; %arrange X coordinate data
% Y=unique(g_data_y)'; %arrange Y coordinate data
%%Axis, Coordinate Range
x_lb = -7.5; x_ub = 7.5; %y axis low and upper bound [m]
z_lb = -15; z_ub = 0.0; %y axis low and upper bound [m]
TickIntX = 2.5; TickIntZ = 2.5; %Tick interval
x_t = x_lb:TickIntX:x_ub; %Graph x axis
z_t = z_lb:TickIntZ:z_ub; %Graph y axis
%%Grid Resolution
MeshRes_x = x_lb:0.02:x_ub; %Set grid resolution x
MeshRes_z = z_lb:0.04:z_ub; %Set grid resolution y
%%Make the Mesh Data
[xi, yi]=meshgrid(MeshRes_x, MeshRes_z); %Make meshgrid
T1=griddata(GridDataX1',GridDataZ1',GridDataT1', xi,yi); %make temp matrix
T2=griddata(GridDataX2',GridDataZ2',GridDataT2', xi,yi);
%%Plot Setting - Font size
FS_ti = 13; %font size of title
FS_xlab = FS_ti+1; FS_ylab=FS_ti+1; %font size of axis label
FS_conla = FS_ti-2; %font size of contourf label
FS_AxTick = FS_ti-1; %font size of axis tick
FS_CBar = FS_ti-2; %font size of color bar
LabelSpc = 200; %label spacing
ContLB = [MinT1, MinT2];
ContUB = [MaxT1, MaxT2];
%%Contour Range, Interval
% con_lb = min(ContLB); con_ub = max(ContUB); %contourf lower bound and upper bound
% con_res = 0.2; %contourf interval resolution
% conlevel=(con_lb:con_res:con_ub); %contour step specify
Cont_lb1 = MinT1; Cont_ub1 = MaxT1; %contourf lower bound and upper bound
con_res1 = 1.0; %contourf interval resolution
conlevel1=(Cont_lb1:con_res1:Cont_ub1); %contour step specify
Cont_lb2 = MinT2; Cont_ub2 = MaxT2; %contourf lower bound and upper bound
con_res2 = 1; %contourf interval resolution
conlevel2=(Cont_lb2:con_res2:Cont_ub2); %contour step specify
%%Line Width
LineWId=0.5; %Graph line width
%%Figure 1
figure(1);
[c1,h1] = contourf(xi,yi,T1,conlevel1,'LineStyle', 'None', 'LineWidth',LineWId); %contourf, countourf, linestyle, linewidth
title ('(b) \ity \rm= 0 m','FontSize',FS_ti, 'FontName','Times New Roman');
clabel(c1,h1, 'LabelSpacing', LabelSpc, 'FontSize', FS_conla, 'FontName','Times New Roman'); %label'manual'-manual labeling 'LabelSpacing', labelspc,
xlabel('\itx \rm[m]','FontSize',FS_xlab,'FontName','Times New Roman', 'FontAngle', 'italic'); %x label font, font size
ylabel('\itz \rm[m]','FontSize',FS_ylab,'FontName','Times New Roman', 'FontAngle', 'italic'); %y label font, font size
set(gca, 'XTick',x_t, 'YTick',z_t, 'XMinorTick', 'off', 'YMinorTick', 'off' ); %X, Y axis tick, Minor tick, plot aspect ratio
set(gca, 'FontSize',FS_AxTick, 'FontName','Times New Roman', 'LineWidth',0.5); %axis index font, color, line width
set(gca, 'XGrid' , 'on' , 'YGrid' , 'on', 'GridLineStyle', ':', 'LineWidth',0.1); %grid on off line style
caxis([Cont_lb1 Cont_ub1]); %color bar range
colorbar('FontName','Times New Roman','FontSize',FS_CBar); %color bar font
colormap (jet); %Jet, Hot, Cool, http://www.mathworks.co.jp/jp/help/matlab/ref/colormap.html
axis ([x_lb, x_ub, z_lb, z_ub]); %x, y axis min max
axis square; %equal, sqaure, auto, tight
brighten(0.5); %brightness
set(gcf, 'Units', 'centimeters', 'position', [6 4 13 13]); %Position starts from left down corner, then define size of figure
%%Figure 2
figure(2);
set(gcf, 'Units', 'centimeters', 'position', [6 4 13 13]); %Position starts from left down corner, then define size of figure
[c2,h2] = contourf(xi,yi,T2,conlevel2,'LineStyle', 'None', 'LineWidth',LineWId); %contourf, countourf
title ('(c) \ity \rm= 7.5 m ','FontSize',FS_ti, 'FontName','Times New Roman'); %Title
clabel(c2,h2, 'LabelSpacing', LabelSpc, 'FontSize', FS_conla, 'FontName','Times New Roman'); %label'manual'-manual labeling 'LabelSpacing', labelspc,
xlabel('\itx \rm[m]','FontSize',FS_xlab,'FontName','Times New Roman', 'FontAngle', 'italic'); %x label font, font size
ylabel('\itz \rm[m]','FontSize',FS_ylab,'FontName','Times New Roman', 'FontAngle', 'italic'); %y label font, font size
set(gca, 'XTick',x_t, 'YTick',z_t, 'XMinorTick', 'off', 'YMinorTick', 'off'); %X, Y axis tick, Minor tick, plot aspect ratio
set(gca, 'FontSize',FS_AxTick, 'FontName','Times New Roman', 'LineWidth',0.5); %axis index font, color, line width
set(gca, 'XGrid' , 'on' , 'YGrid' , 'on', 'GridLineStyle', ':', 'LineWidth',0.1); %grid on off line style
caxis([Cont_lb2 Cont_ub2]); %color bar range
colorbar('FontName','Times New Roman','FontSize',FS_CBar); %color bar font
colormap (jet); %Jet, Hot, Cool, http://www.mathworks.co.jp/jp/help/matlab/ref/colormap.html
axis ([x_lb, x_ub, z_lb, z_ub]); %x, y axis min max
axis square; %equal, sqaure, auto, tight
brighten(0.5); %brightness
set(gcf, 'Units', 'centimeters', 'position', [6 4 13 13]); %Position starts from left down corner, then define size of figure
%%Save the Plot
%%No margin%%
% style.Bounds = 'Tight';
% style = hgexport( 'factorystyle' );
% hgexport( gcf, '-Clipboard', style, 'ApplyStyle', true ); %figure export, -Clipboard:Copy to clipboard
print('-f1', '-dmeta','-r600','ContourXZ1'); %Save the graph, figrue1, filetype(-dmeta,-depsc), resolution 600, filename
print('-f2', '-dmeta','-r600','ContourXZ2');
disp('Calculation is Done');
  1 Comment
Gideon simpson
Gideon simpson on 26 Nov 2014
Mathworks really needs to address these graphics issues. I've gone back to 2014a because of all that. Does mathworks expect us to wait until 2015a comes out before we have a working product?

Sign in to comment.

Answers (1)

Rob Comer
Rob Comer on 5 Jun 2015
Regarding part 1 of this question, you can control the contour label FontName and other label text properties in R2014b or R2015a, as in this example:
[C,h] = contour(peaks);
clabel(C,h,'LabelSpacing',64,'FontSize',16,'FontName','Times New Roman')
if you download and install one of the workarounds that is available here: http://www.mathworks.com/support/bugreports/1114747. (There are separate workarounds for R2014b and R2015a.) For calls to clabel that include the contour object handle h, the workaround will enable you to specify a total of 12 properties that affect the appearance of contour labels: Color, FontName, FontSize, FontWeight, and 8 others.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by