在 pdf 中嵌入 matlab 图以进行打印:尺寸

发布于 2024-11-18 17:53:32 字数 630 浏览 3 评论 0原文

我目前正在 matlab 中创建我的图形,通过 Latex 将它们嵌入到 pdf 中以供以后打印。我保存这些数字并通过脚本 export_fig 保存它们!现在我想知道最好的方法是什么:

  • 选择哪个尺寸的 matlab 图形窗口
  • 为脚本采用哪个 -m 选项?它将改变图像的分辨率和大小...

我想知道与以下两点有关的这些点:

  1. 当选择更大的图形尺寸时,会显示更多的刻度线,并且单点标记更明显
  2. 当使用小数字并使用大-m选项时,我仍然只有一些刻度线
  3. 当我生成相当大的图像时(例如分辨率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:

  1. When chosing the figure-size bigger, there are more tickmarks shown and the single point markers are better visible
  2. When using a small figure and using a big -m option, I still have only some tickmarks
  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那片花海 2024-11-25 17:53:32

MATLAB 绘图在内部描述为矢量图形,PDF 文件也使用矢量图形进行描述。将绘图渲染为光栅格式是一个坏主意,因为您最终必须选择分辨率并最终得到更大的文件。

只需将绘图保存为 EPS 格式,即可使用 直接嵌入到 PDF 文件中乳胶。我通常使用以下命令保存 MATLAB 绘图以供发布:

saveas(gcf, 'plot.eps', 'epsc');

并使用以下命令将它们直接嵌入到我的乳胶文件中:

\includegraphics[width=0.7\linewidth]{plot.eps}

然后,您只需选择图像所占线条的比例(在本例中为 70%)。

编辑:IrfanView 和其他 (XnView) 不能很好地显示 EPS。您可以在 Adob​​e Illustrator 中打开它们,以更好地预览其外观。我总是以这种方式插入我的绘图,它们在 PDF 中看起来总是与在 MATLAB 中完全相同。

使用 EPS 还可以获得的一个好处是,您实际上可以指定字体大小,这样即使您调整文档中的图像大小,文本也可读。

至于刻度数,你可以查看axes属性 MATLAB 文档。特别是,无论窗口分辨率如何,XTickYTick 属性对于手动控制显示的刻度数非常有用。

编辑(再次):如果您将图像渲染光栅格式(例如 PNG),最好选择完全相同的分辨率正如文档中使用的那样。渲染大图像(通过使用大窗口大小)并在 PDF 中将其变小会产生不好的结果,主要是因为文本的大小将直接随图像的大小缩放。渲染小图像显然会因为拉伸而产生非常糟糕的效果。

这就是为什么您应该使用矢量图像格式。然而,图形的默认 MATLAB 设置会产生一些与光栅图像相同的问题:文本大小未指定为字体大小,并且刻度数随窗口大小而变化。

要在最终渲染中生成最佳绘图,请按照以下步骤操作:

  1. 将图形的字体大小设置为合适的设置(例如 11pt)
  2. 渲染绘图
  3. 确定刻度数以获得良好效果并手动设置刻度
  4. 将图像渲染为颜色EPS

在 MATLAB 代码中,这应该类似于以下内容:

function [] = nice_figure ( render )
    %
      % invisible figure, good for batch renders.
    f = figure('Visible', 'Off');
      % make plots look nice in output PDF.
    set(f, ...
        'DefaultAxesFontSize', 11, ...
        'DefaultAxesLineWidth', 0.7, ...
        'DefaultLineLineWidth', 0.8, ...
        'DefaultPatchLineWidth', 0.7);
      % actual plot to render.
    a = axes('Parent', f);
      % show whatever it is we need to show.
    render(a);
      % save file.
    saveas(f, 'plot.eps', 'epsc');
      % collect garbarge.
    close(f);
end

然后,您可以使用以下方法绘制一些奇特的图:

function [] = some_line_plot ( a )
    %
      % render data.
    x = -3 : 0.001 : +3;
    y = expm1(x) - x - x.^2;
    plot(a, x, y, 'g:');
    title('f(x)=e^x-1-x-x^2');
    xlabel('x');
    ylabel('f(x)');
      % force use of 'n' ticks.
    n = 5;
    xlimit = get(a, 'XLim');
    ylimit = get(a, 'YLim');
    xticks = linspace(xlimit(1), xlimit(2), n);
    yticks = linspace(ylimit(1), ylimit(2), n);
    set(a, 'XTick', xticks);
    set(a, 'YTick', yticks);
end

并使用以下方法渲染最终输出:

nice_figure(@some_line_plot);

使用这样的代码,您根本不需要担心窗口大小。请注意,我什至没有显示窗口供您调整其大小。使用此代码,我总是能得到漂亮的输出和较小的 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:

saveas(gcf, 'plot.eps', 'epsc');

and embed them directly into my latex file using:

\includegraphics[width=0.7\linewidth]{plot.eps}

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 and YTick 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:

  1. Set the figure's font size to a decent setting (e.g. 11pt)
  2. Render the plot
  3. Decide on number of ticks to get a good effect and set the ticks manually
  4. Render the image to color EPS

In MATLAB code, this should look somewhat like the following:

function [] = nice_figure ( render )
    %
      % invisible figure, good for batch renders.
    f = figure('Visible', 'Off');
      % make plots look nice in output PDF.
    set(f, ...
        'DefaultAxesFontSize', 11, ...
        'DefaultAxesLineWidth', 0.7, ...
        'DefaultLineLineWidth', 0.8, ...
        'DefaultPatchLineWidth', 0.7);
      % actual plot to render.
    a = axes('Parent', f);
      % show whatever it is we need to show.
    render(a);
      % save file.
    saveas(f, 'plot.eps', 'epsc');
      % collect garbarge.
    close(f);
end

Then, you can draw some fancy plot using:

function [] = some_line_plot ( a )
    %
      % render data.
    x = -3 : 0.001 : +3;
    y = expm1(x) - x - x.^2;
    plot(a, x, y, 'g:');
    title('f(x)=e^x-1-x-x^2');
    xlabel('x');
    ylabel('f(x)');
      % force use of 'n' ticks.
    n = 5;
    xlimit = get(a, 'XLim');
    ylimit = get(a, 'YLim');
    xticks = linspace(xlimit(1), xlimit(2), n);
    yticks = linspace(ylimit(1), ylimit(2), n);
    set(a, 'XTick', xticks);
    set(a, 'YTick', yticks);
end

And render the final output using:

nice_figure(@some_line_plot);

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文