Problem in printing with bodeplot function
5 次查看(过去 30 天)
显示 更早的评论
Hi all,
I try to get some Bode plots and print the figure with specific width and length. However, the resultant figure places the window such that the x axis label stays out of the window and y axis is partly out of the window depending on the PaperSize dimensions (for example with the values in the code below). I want Matlab to configure the plot such that the all the x axis, y axis labels, title, etc. stay inside the visible window and print in that way. Any help is appreciated. Below is the main function with bodeplot
sys = rss(5);
opts1=bodeoptions('cstprefs');
opts.FreqUnits = 'Hz';
opts1.XLim={[100 20000]};
bodeplot(sys,opts1);
grid on; title('');
width = 8.8; % in cm
height = 6; % in cm
fontsize = 10;
filename = 'bode';
setfig(gcf, filename, width, height, fontsize);
print(gcf, '-dpdf', filename);
and below is the setfig function
function out = setfig(varargin)
if nargin > 0
if isempty(varargin{1})
figno = gcf;
else
figno = varargin{1};
end;
else
figno = gcf;
end;
if nargin > 1
filename = varargin{2};
else
filename = [];
end;
if nargin > 2
if isempty(varargin{3})
width=8.8;
else
width = varargin{3};
end;
else
width=8.8;
end
if nargin > 3
if isempty(varargin{4})
height = width;
else
height = varargin{4};
end;
else
height = width;
end
if nargin > 4
if isempty(varargin{5})
fontsize = 10;
else
fontsize = varargin{5};
end;
else
fontsize = 10;
end
if nargin > 5
if isempty(varargin{6})
fontname = 'Times New Roman';
elseif varargin{6} == 'nc'
fontname = '';
else
fontname = varargin{6};
end;
else
fontname = 'Times New Roman';
end
set(figno, 'Renderer', 'Painters');
set(figno, 'PaperUnits', 'Centimeters');
set(figno, 'PaperSize', [width height]);
set(figno, 'PaperPositionMode', 'auto');
set(figno, 'PaperPosition', [0 0 width height]);
ppos = get(figno,'PaperPosition');
su = get(figno,'Units');
pu = get(figno,'PaperUnits');
set(figno,'Units',pu);
spos = get(figno,'Position');
set(figno,'Position',[spos(1) spos(2) ppos(3) ppos(4)])
set(figno,'Units',su)
% Set all fonts on the current figure
allaxes = findall(figno, 'Type','axes');
for k = 1:length(allaxes)
set([allaxes(k); findall(allaxes(k), 'Type','text')], 'FontSize', fontsize, 'FontName', fontname);
end
out =figno;
if ~isempty(filename)
print (figno,'-depsc', filename)
end
0 个评论
回答(1 个)
Jyotsna Talluri
2020-3-3
You can increase the height and width dimensions of the paper size .On setting the height and width to 10 would fit the entire plot in the figure
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Plot Customization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!