Oliver Amundsen
Oliver Amundsen

Reputation: 1511

Matlab - Smoothing crooked and aliased lines in plots

I'm sure this has an easy solution, but I can't get a way out of it. When I plot a thick line in Matlab and print it (r550) I get the crooked line seen below. I tried the 'smooth' command to no avail. Here's the code:

plot(x,y1,'b','LineWidth',8);hold on 
plot(x,y2,'r','LineWidth',8);hold on
print -djpeg -r550 figure1

here's the blue line values (y1):

y1 = [1.9   1.81    1.73    1.65    1.63    1.6 1.65    1.59    1.54    1.52    1.47    1.52    1.53    1.48    1.44    1.43    1.‌​39  1.38    1.34    1.33    1.33    1.32 1.29   1.26    1.23    1.22    1.24    1.23    1.21    1.22    1.22    1.2 1.25‌​  1.25    1.22    1.22    1.2 1.18    1.19    1.17    1.15    1.13    1.15    1.13 1.11   1.09    1.08    1.07    1.12    1‌​.1   1.1 1.08    1.08    1.07    1.05    1.04    1.03    1.01    1.01    1.01    1.01    1   1   1   1   1   0.99    1.01    1.01‌​ 1.01 1   0.99    0.98    0.98    0.98    0.97    0.97    0.97    0.97    0.97    0.97    0.96    0.96    0.96    0.96    0.9‌​5  0.95    0.99    0.98    1   0.99    0.98 0.98   0.98    0.98    0.98    0.97    0.97    0.97    0.96    0.95    0.94    0.‌​94  0.93    0.93    0.93    0.92    0.93    0.92    0.91    0.92    0.92    0.91 0.92   0.93    0.92    0.91    0.91    0.9‌​1  0.9 0.89    0.89    0.89    0.88    0.88]; 

Any help to make it look nice and smooth? Thanks!

enter image description here

---------WITH DMETA--------------

I used a resolution of 600dpi. Next figure doesn't look bad, but in a Word file or Powerpoint doesn't shows as good. Any ideas??

enter image description here

Upvotes: 1

Views: 494

Answers (2)

Trogdor
Trogdor

Reputation: 1346

This problem is caused by how matlab renders objects for saving.

One thing you could try is the HG2 update to MATLAB (link). It is a MAJOR improvement to how visually appealing graphics are, however it can cause matlab to crash.

A workaround that you might find good enough is to add a marker plot for each data line. such as

plot(x,y1,'.b','MarkerSize',24);

Placing a marker at each node will fill in the rough edges of the plot. You might have to play around with the marker size a little.

Upvotes: 1

Oleg
Oleg

Reputation: 111

If you work in Windows, the good option is to export to a windows meta file (.emf) instead of jpeg:

print -dmeta figure1

Additionally, it looks much better in MS Office documents (vector format). You can always convert emf to jpeg if required.

Upvotes: 2

Related Questions