print figure to pdf - each plotted line gets split into smaller segments, leaving small gaps between them

2 ビュー (過去 30 日間)
Consider the following simple code:
clf
hold on
x = linspace(0,3*pi,600);
plot(x,sin(x),'k--','LineWidth',20)
plot(x,cos(x),'r-','LineWidth',20)
ylim([-1.2,1.2])
print('-dpdf','-r800','TestFig.pdf')
In the file 'TestFig.pdf' (highlighted by blue circles in attached image), it appears that the red and black line plots have been broken into smaller segments. You can see this e.g. at the top of the red peak (around x=2*pi), where there is a small white gap. You can also see this at various points along the dashed line (e.g. around x=pi); where one line segment stops and the next starts, the dash pattern is broken.
The number of data points in each line is 600. It appears this is being split up into line segments roughly 100 data points in length each. I wonder whether the print function is intentionally splitting the lines into smaller segments, and if so whether there is some way of stopping this happening so that each line is one uninterrupted vector object. Currently I am having to do this manually in Inkscape afterwards (where each segment is a different vector graphic object).
The choice of linewidth (20) and resolution ('-r800') is to exaggerate the effect. The problem still appears for other linewidths and resolutions. It also appears when printing to other vector graphic formats (e.g. .eps), although not for bitmaps (e.g. .png).
I've checked this on Matlab 2012 and 2014, on Ubuntu, Windows and OSX, all of which give the same behaviour.

採用された回答

Rebecca Krosnick
Rebecca Krosnick 2016 年 1 月 22 日
When I changed the number of points to 100 it seems the curves are no longer broken up into segments. I do not see those gaps. I also do not see the overlapping black dashes on the flat part of the curve. I however do still see the overlapping dashes at the very curvy parts of the curve, but I think that is unavoidable.
I also tried running your code in MATLAB R2014b, and with 600 points the gaps have disappeared, so you might want to try R2014b if you have access.
  2 件のコメント
DrB
DrB 2016 年 1 月 23 日
編集済み: DrB 2016 年 1 月 23 日
Thanks both!
Yes I tried this on MATLAB R2015b and the problem seems to be fixed as you said.
Looking at the lines produced by R2015b in Inkscape (where you can select individual sections using the 'edit path by nodes (F2)' tool), the red line is still split into several segments, however the sections are now overlapping (i.e. if a line is split into two segments, some of the data points in each segment overlap into the other), which removes the unsightly gaps. For the dashed line, it now hasn't been split into segments which means there is no break in the dashed pattern as there was before and the dashes appear evenly.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

タグ

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by