3
votes

This question maybe a bit like the link below, but this didn't work for me... http://nl.mathworks.com/matlabcentral/answers/102530-how-can-i-change-the-default-settings-for-the-linewidth-property-before-i-plot-a-figure-in-matlab

I'm working on a matlab function that automatically opens your figure in full screen mode and on a second monitor if present. So far, everything works fine. I already achieved to set the fontsize inside the function, so whitout plotting anything and without making xlabel(..) etc.:

% Fontsize used at the figure
if ~exist('fontsize_manual','var')|| isempty(fontsize_manual)
    set(gca,'FontSize',16)
else
    set(gca,'Fontsize',fontsize_manual)
end

Now is my question: Can I change in a same way the linewidth of the lines that will by plotted in the figure? So also here, predefining the linewidth inside the function and later on in your script plotting some lines etc. I do prefer this works only for the figure you're working on, so that you can change this 'default' for each figure and save them all with different linewidth and fontsizes if needed.

I tried the line below, but that only changed the linewidth of the axis.

set(gca,'LineWidth',2)

Is there anyone who can help me solving this problem?

%------------------------------------------------------------------------------------------------------------------------------ The answer below is nice, but I detected a new problem. The code below in found accidentally by solving the previous problem:

set(gca,'LineWidth',3)

It turned out this changes the width of the axes. But now the problem... Also here this works only on the first figure. (see figure) enter image description here

If I also put this code in my session after the plotting in the second figure, the width in the second figure changes. Looks like the right handle isn't reached, or something like that, inside the function, when making the second figure. Do you have any idea what could be wrong here?

2

2 Answers

5
votes

I think what you are after is the DefaultLineLineWidth property, to which you can assign a value for a particular figure (or the root).

Here is a simple code illustrating; basically I create a figure, set its 'visible' property to 'off' and assign a default line linewidth (that sounds weird...). The line plotted has a linewidth of 4, whereas another plot created after has the default width:

clear
clc

hFig1 = figure('Visible','off'); %// Create figure, set it to not visible.

set(gcf,'DefaultLineLineWidth',4); %// Assign default linewidth.

x = 1:10;
plot(x,x.^2-5);

set(hFig1,'Visible','on')
title('Figure 1','FontSize',16);

hFig2 = figure;
plot(x,2.*x+rand(1,10));
title('Figure 2','FontSize',16);

Plots:

enter image description here

enter image description here

Hope that help!

4
votes

The link shown sets the property of the root (and so all figures should inherit). (This worked for me)

set(0,'defaultlinelinewidth',2)

You can also try a similar set command like the one you suggested, but change it to this:

set(gcf,'defaultlinelinewidth',2)