在 pdf 中嵌入 matlab 图以进行打印:尺寸
我目前正在 matlab 中创建我的图形,通过 Latex 将它们嵌入到 pdf 中以供以后打印。我保存这些数字并通过脚本 export_fig 保存它们!现在我想知道最好的方法是什么:
- 选择哪个尺寸的 matlab 图形窗口
- 为脚本采用哪个
-m
选项?它将改变图像的分辨率和大小...
我想知道与以下两点有关的这些点:
- 当选择更大的图形尺寸时,会显示更多的刻度线,并且单点标记更明显
- 当使用小数字并使用大
-m
选项时,我仍然只有一些刻度线 - 当我生成相当大的图像时(例如分辨率300和仍然2000* 2000 像素)然后将其嵌入到文档中:这看起来丑吗?这是否会以良好的缩放模式嵌入,或者是否与您将 1000*1000px 图像上传到主页并通过 html 中的宽度和高度标签嵌入它一样丑陋 ->浏览器显示它非常难看,因为浏览器没有进行
真正的
调整大小。所以看起来不清晰而且丑陋。
提前致谢!
I'm currently creating my figures in matlab to embed themvia latex into a pdf for later printing. I save the figures and save them via the script export_fig! Now I wonder which is the best way to go:
- Which size of the matlab figure window to chose
- Which
-m
option to take for the script? It will change the resolution and the size of the image...
I'm wondering about those points in regards to the following two points:
- When chosing the figure-size bigger, there are more tickmarks shown and the single point markers are better visible
- When using a small figure and using a big
-m
option, I still have only some tickmarks - When I generate a image which is quite huge (e.g. resolution 300 and still 2000*2000px) and than embed it into the document: Does this than look ugly? Will this be embedded in a nice scaling mode or is it the same ugliness as if you upload a 1000*1000px image onto a homepage and embed it via the widht and height tags in html -> the browser displays it quite ugly because the browser doesn't do a
real
resize. So it looks unsharp and ugly.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MATLAB 绘图在内部描述为矢量图形,PDF 文件也使用矢量图形进行描述。将绘图渲染为光栅格式是一个坏主意,因为您最终必须选择分辨率并最终得到更大的文件。
只需将绘图保存为 EPS 格式,即可使用
直接嵌入到 PDF 文件中乳胶。我通常使用以下命令保存 MATLAB 绘图以供发布:
并使用以下命令将它们直接嵌入到我的乳胶文件中:
然后,您只需选择图像所占线条的比例(在本例中为 70%)。
编辑:IrfanView 和其他 (XnView) 不能很好地显示 EPS。您可以在 Adobe Illustrator 中打开它们,以更好地预览其外观。我总是以这种方式插入我的绘图,它们在 PDF 中看起来总是与在 MATLAB 中完全相同。
使用 EPS 还可以获得的一个好处是,您实际上可以指定字体大小,这样即使您调整文档中的图像大小,文本也可读。
至于刻度数,你可以查看axes属性 MATLAB 文档。特别是,无论窗口分辨率如何,
XTick
和YTick
属性对于手动控制显示的刻度数非常有用。编辑(再次):如果您将图像渲染为光栅格式(例如 PNG),最好选择完全相同的分辨率正如文档中使用的那样。渲染大图像(通过使用大窗口大小)并在 PDF 中将其变小会产生不好的结果,主要是因为文本的大小将直接随图像的大小缩放。渲染小图像显然会因为拉伸而产生非常糟糕的效果。
这就是为什么您应该使用矢量图像格式。然而,图形的默认 MATLAB 设置会产生一些与光栅图像相同的问题:文本大小未指定为字体大小,并且刻度数随窗口大小而变化。
要在最终渲染中生成最佳绘图,请按照以下步骤操作:
在 MATLAB 代码中,这应该类似于以下内容:
然后,您可以使用以下方法绘制一些奇特的图:
并使用以下方法渲染最终输出:
使用这样的代码,您根本不需要担心窗口大小。请注意,我什至没有显示窗口供您调整其大小。使用此代码,我总是能得到漂亮的输出和较小的 EPS 和 PDF 文件大小(比使用 PNG 时小得多)。
该解决方案唯一解决的问题是当乳胶代码中的绘图变大时添加更多刻度,但无论如何这是无法做到的。
The MATLAB plots are internally described as vector graphics, and PDF files are also described using vector graphics. Rendering the plot to a raster format is a bad idea, because you end up having to choose resolution and end up with bigger files.
Just save the plot to EPS format, which can be directly embedded into a PDF file using
latex
. I usually save my MATLAB plots for publication using:and embed them directly into my latex file using:
Then, you only need to choose the proportion of the line the image is to take (in this case, 70%).
Edit: IrfanView and others (XnView) don't display EPS very well. You can open them in Adobe Illustrator to get a better preview of what it looks like. I always insert my plots this way and they always look exactly the same in the PDF as in MATLAB.
One bonus you also get with EPS is that you can actually specify a font size so that the text is readable even when you resize the image in the document.
As for the number of ticks, you can look at the axes properties in the MATLAB documentation. In particular, the
XTick
andYTick
properties are very useful manually controlling how many ticks appear no matter what the window resolution is.Edit (again): If you render the image to a raster format (such as PNG), it is preferable to choose the exact same resolution as the one used in the document. Rendering a large image (by using a big window size) and making it small in the PDF will yield bad results mainly because the size of the text will scale directly with the size of the image. Rendering a small image will obviously make for a very bad effect because of stretching.
That is why you should use a vector image format. However, the default MATLAB settings for figures produce some of the same problems as raster images: text size is not specified as a font size and the number of ticks varies with the window size.
To produce optimal plots in the final render, follow the given steps:
In MATLAB code, this should look somewhat like the following:
Then, you can draw some fancy plot using:
And render the final output using:
With such code, you don't need to worry about the window size at all. Notice that I haven't even showed the window for you to play with its size. Using this code, I always get beautiful output and small EPS and PDF file sizes (much smaller than when using PNG).
The only thing this solution does not address is adding more ticks when the plot is made larger in the latex code, but that can't be done anyways.