Categories
Software

Change font name in Bode plot

I had been struggling with this problem a while before I did manage to find a work around. It was actually quite important for me to change the font name in Bode plots because I decided to use everywhere Cambria in my report. Normally Heveltiva is used by default in Matlab.

In general it is possible to change font in Matlab plots without any problems. But this is in case the standard package. It should be emphasized that each of Matlab toolboxes is developed by separated teams of specialists. That is why sometimes different features can be solved with a different approach and actually in Control System Toolbox it is not predicted to change font name. You can change the size or style but not the name.

Available parameters for different labels in case of Bode, Nyquist, etc. plots are the following

>> PlotHandle= bodeplot(TrunsferFunction);
>> PlotOptions= getoptions(PlotHandler);
>> PlotOptions.Title,
ans =

String: 'Dummy Title'
FontSize: 10
FontWeight: 'normal'
FontAngle: 'normal'
Color: [0 0 0]
Interpreter: 'tex'

As everyone can see there is not option defining the font name. Fortunately there is some space to deal with it due to the fact that it is possible to define the interpreter. In Tex it is actually possible to define font name locally in text. This can be done in the following way

PlotOptions.Title.String= '';
PlotOptions.XLabel.String= '\fontname{Cambria}{\itf}';
PlotOptions.XLabel.FontSize= 10;
PlotOptions.YLabel.String= {'\fontname{Cambria}|{\itG_{ol}}|',...
    '\fontname{Cambria}\angle{\itG_{ol}}'};
PlotOptions.YLabel.FontSize= 10;
PlotHandle.setoptions(PlotOptions),

And here is the final result.

Bode Plot Font NameAnother solution is to get the frequency response into arrays and display results using functions form Matlab base package. In this case it is also possible to change axes font name.

You can also change the default system font for all figures and axes by putting the following code at the beginning of your m-file. Please note that this will change your default font during your Matlab session. I do this quite often if I do not want to think so much preparing figures for printing.

fontname= 'Cambria';
set(0,'defaultaxesfontname',fontname);
set(0,'defaulttextfontname',fontname);
fontsize= 10;
set(0,'defaultaxesfontsize',fontsize);
set(0,'defaulttextfontsize',fontsize);

Hope this helps and looking forward to see some comments.