Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to precisely control line thickness in MATLAB plot?

I would like to precisely control the thickness of the line plotted in MATLAB. Not just 0.5, 1, 2, 3, ... points but e.g. 0.2mm. Is it possible?

There is a custom line scale and minimum line width box in the export setup window but that does not work.

enter image description here

Sample code:

hf = figure;
ha = axes;
ha.Units = 'centimeters';

t = linspace(0,2*pi);
hl = plot(t,sin(t),'Linewidth',0.1);
axis tight

saveas(hf,'test','pdf')
like image 285
Szymon Bęczkowski Avatar asked Apr 21 '15 18:04

Szymon Bęczkowski


People also ask

How is Axis line thickness set?

go to edit -> axes properties and this will open up a property inspector. within this select "box styling" option and see the value for "LineWidth".

How do you change the thickness of line line style line color and marker properties of a chart?

Right-click the line you want to change and click Properties. Under Line, choose a color from the Color list and a line thickness from the Line list.

How do I change the thickness of a line in Matplotlib?

Matplotlib allows you to adjust the line width of a graph plot using the linewidth attribute. If you want to make the line width of a graph plot thinner, then you can make linewidth less than 1, such as 0.5 or 0.25.


1 Answers

MatLab uses the standard definition of 1 PostScript Point (or "Desktop Publishing Point") = 1/72 inches.

(You can confirm this easily by exporting a figure with, say, a line with 'LineWidth' equal to 36. If you print that without scaling, the line on the paper will be 1/2 inch wide)

So if you want a line of 0.2 mm, you can set the line width to 0.567 or so:

h = plot([0 0],[0 1]);
set(h,'LineWidth',0.567);

and if you want to set that as the default line width for all your plots:

 set(0,'defaultlinelinewidth',0.567)

for a single session, or put into your startup.m file to set it permanently.

In response to @szymon-bęczkowski: with 2014b and later, there seems to be a bug in Matlab that sets the linewidth to a minimum value of 1 when exporting to EPS or PDF. See here for a related bug. So the 'workaround' as it is, is to stick to linewidth>=1.

Although it doesn't seem to work there either, I strongly recommend export_fig as an alternative to Matlab's built it printing capabilities.

like image 143
Carlos Avatar answered Nov 15 '22 17:11

Carlos