Matlab: How to change the line width in a shape before drawing some of them?
This question might be a bit like the link below, but it 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 am working on a matlab function that automatically opens your shape full screen and on a second monitor if present. Everything works fine so far. I have already managed to set the font inside the function, so I don't draw anything or do 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 my question is: can I also change the line width of the lines that will be built according to the picture? Same here, by predetermining the line width inside the function, and then in your script, building some lines, etc. I prefer that this only work for the shape you are working on so that you can change this default for each shape and keep them all with different line widths and fonts as needed.
I tried the line below, but that only changed the axis line width.
set(gca,'LineWidth',2)
Is there anyone who can help me solve this problem?
% ---------------------------------------------- --- ----------------------------------------------- --- --------------------------- The answer below is good, but I found a new problem. The code below is found by accident, solving the previous problem:
set(gca,'LineWidth',3)
It turned out that this changes the width of the axes. But now the problem ... And here it only works in the first picture. (see picture)
If I also put this code in my session after the graph in the second picture, the width in the second picture changes. It looks like the correct handle was not reached or something inside the function when creating the second shape. Do you know what could be wrong here?
source to share
I think you are following a property DefaultLineLineWidth
that you can assign a value to a specific shape (or root).
Here's a simple code to illustrate; basically I create a shape, set its "visible" property to "off" and assign a line to the default line width (which sounds weird ...). The line has a line width of 4, whereas the other graph created after has a 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:
Hope it helps!
source to share