matlab作图 latex插图

推荐用saveas eps,再用eps2pdf转成pdf。这样可以之间pdflatex编译。

if result.savepic

saveas(gcf,[ pwd '/picture/right_' num2str(problem.numsamples) '_' num2str(problem.Ttest) problem.name '.fig']);

saveas(gcf,[ pwd '/picture/right_' num2str(problem.numsamples) '_' num2str(problem.Ttest) problem.name '.eps'],'epsc'); %带彩色

eps2pdf([pwd '/picture/right_' num2str(problem.numsamples) '_' num2str(problem.Ttest) problem.name '.eps']);

end

%template
result.linspec = {'r.-','b*-','go-','rs-','b^-','gd-'}; load pgsd figure for j=2:5 tmp1=[]; index=[]; for i=1:length(a(1,:)) if a(j,i)~=0 tmp1=[tmp1 a(j,i)]; index=[index a(1,i)]; end end plot(index,tmp1,result.linspec{j});hold on; end grid on legend('SGD','SGD+AdaGrad','pSGD+AdaGrad','pSGD','Location','SouthEast') xlabel('Training Time (min) ') ylabel('Accuracy (%) ') figure_FontSize=20; set(get(gca,'XLabel'),'FontSize',figure_FontSize,'Vertical','top'); set(get(gca,'YLabel'),'FontSize',figure_FontSize,'Vertical','middle'); set(findobj('FontSize',10),'FontSize',figure_FontSize); set(findobj(get(gca,'Children'),'LineWidth',0.5),'LineWidth',2.3); %set(findobj(get(gca,'Children'),'MakerSize',1),'MakerSize',5); set(gca,'FontSize',figure_FontSize) saveas(gcf,[ pwd '/map5_boldfi' '.fig']); saveas(gcf,[ pwd '/map5_boldfi' '.eps'],'epsc'); eps2pdf( [pwd '/map5_boldfi' '.eps']); % Place second set of axes on same plot % % handaxes2 = axes('position', [0.2 0.5 0.4 0.3]); % % set(handaxes2, 'box', 'off'); % % semilogx(cumsum(parametertmp),cputimetmp./gputimetmp); % % Adjust XY label font % xlabel('Parameter number'); % ylabel('Speed gain ratio'); % grid on % set(get(handaxes2, 'xlabel'), 'fontname', 'times') % set(get(handaxes2, 'ylabel'), 'fontname', 'times') % %title('Comparision of LSTM Efficiency with CPU and GPU ')

多个插图并排,互不相关。

\usepackage{floatrow}
\begin{figure}
\begin{floatrow}[2]
\ffigbox{ \caption{Various Sigmoid functions and their derivatives} \label{sigmoidfunction} }{\includegraphics[width=6.5cm]{picture//sigmoid} }
\ffigbox{ \caption{Experiments with different sigmoid functions (lbfgs)}
\label{newexcitation}}{\includegraphics[width=6.5cm]{picture//newexcitation} }
\end{floatrow}
\end{figure}
相关,用subfloat[caption]{\includegr... \quad(换行)

For Pdftex the best vector format ist PDF. Many programs can output PDF. Inkscape for example has good PDF output. As for raster images PNG is the best as long as you don’t include photopraphs, then it’s good old JPEG.

In plain Latex you can only include EPS, but it depends on how the EPS was generated. EPS can contain both vector and raster images. It’s basically only a container format.

print 最常用

saveas 保存fig文件,图片大小按默认设置

saveas(gcf,'pictures\p.png')

saveas(gca,'myplot.eps','epsc');

Note the c in 'epsc'.

or

print-depsc myplot.eps
可以试一下set(gcf, 'PaperPositionMode','auto')

我曾经用这种方法在1280*960的分辨率下保存过650*1610的图,但是后来试一张800*2760的图仍然是变形,也试过调整纸张大小,都没有效果,一直很困扰,期待高手解答

imwrite 所见即所得,最快。

f=getframe(gcf);

imwrite(f.cdata,'p.ps');

Solution:

The best way to do this would be to export your figure into an Encapsulated PostScript (EPS) format file and then include the EPS file in the LaTeX document. You can export a figure into a EPS format using the PRINT command as follows:

plot(1:10)

print -deps epsFig

This will generate a file called epsFig.eps in your current working directory. You can then include this eps file in your LaTeX document.

One method to include an EPS figure in your LaTeX 2E document is as follows:

1. Include the following line before the \begin{document} statement

\usepackage{graphicx}

2. Use the following template code to include any figure:

\begin{figure}

\centering

\includegraphics{Figure name without .eps extension}

\caption{Insert caption}

\end{figure}

\begin{equation} .... .... \label{eq:no1} \end{equation} ... One can see from Eq.~(\ref{eq:no1}) that ...

In a table or figure environment, the \label command should follow the \caption command (or be part of its argument) since it is the \caption command which generates the number.


http://en.wikibooks.org/wiki/LaTeX/Importing_Graphics#Raster_graphics_vs._vector_graphics
要对latex插图仔细研究,推荐Latex插图指南一文(一般CTEX安装目录下help文件夹graphics.pdf就是了),下边用双引号括起来的都引自此书。PS:本文中代码里的图片文件名在编译时请换成你的电脑里实际有的图片,这个大家应该都懂的。 1、 我用惯word的结果是觉得Latex的图片浮动格式很不习惯,然后我听到这样一段话,觉得有醍醐之感:“ 一、不要使用依赖于图形放置位置的文本。使用如“ 这幅图...” 或“ 下面的图形...” 等短语要求所指的图形需在固定位置。而像“ 图5...” 这样的短语则允许图形出现在任意位置。 二、放松。一些使用者在发现图形没有十分准确的出现在他们所想要的位置时,往往非常着急。这没有必要,图形的放置是LATEX 的工作,最好放松一些。” 为什么Latex不推荐我们让图形准确出现在放置的位置呢?“因为那会导致糟糕的分页,将大片的空白留在页面下方。为得到专家级的排版效果,作者不得不手工调整图形的位置。这种工作是非常乏味的,尤其是几乎每次修改文档都得这样做一次。” Knuth同学当年做tex时,目的就是让我们将注意力集中在文章的内容,而不是排版上。尤其是在做长文章或书时,用word每次修改时插入新的文字都要重新调整图片,很不方便。(其实还好啦,我们的文章都短的像兔子尾巴就觉得word也挺好的) 2、 浮动格式 一个典型的插图语句 \begin{figure}[htbp] \centering \includegraphics[width=6.5cm]{graph.eps} \caption{This is an inserted EPS graphic} \label{fig:graph} \end{figure} 其中[htbp]就是浮动格式
!强制忽略latex默认 “h here 当前位置(default)。将图形放置在正文文本中给出该图形环境的地方。如果本页所剩的页面不够,这一参数将不起作用。 t top 顶部。将图形放置在页面的顶部。 b bottom 底部。将图形放置在页面的底部。 p page ,special page for floating object(比如最后一页) 浮动页。将图形放置在一只允许有浮动对象的页面上。” 我一般使用[htb]这样的组合,只用[h]是没有用的(原因请读者思考)。这样组合的意思就是latex会尽量满足排在前面的浮动格式,就是h-t-b这个顺序,让排版的效果尽量好。反正记住,放轻松。 3、 如果你就是要插在你想插的位置怎么办? 我会这样做:如果tex不让你插在你想插的位置,说明你的图片太大了,你可以试试调整[width=6.5cm]中的大小,让它能够插得下,其实我们在word中也是这样做的。推荐使用\textwidth这个单位。但还是那句话,不要太勉强。 4、 一些图片的并排 如果想要这样的效果,要两张图并列,或几张图排在一起。可以试试下面的模板,效果请自己运行 模板一 \begin{figure}[htbp] \centering \subfigure[sin1]{\label{fig:fft:a} \begin{minipage}[c]{0.5\textwidth} \centering \includegraphics[width=6.5cm]{sin1.eps} \end{minipage}% }%注意这个”%”绝对不能省,可以试试不打%的效果 \subfigure[sin2]{ \begin{minipage}[c]{0.5\textwidth} \centering \includegraphics[width=6.5cm]{sin2.eps} \end{minipage} } \caption{fft}\label{fig:fft} \end{figure} 模板二 \begin{figure}[htbp] \centering \begin{minipage}[c]{0.5\textwidth} \centering \includegraphics[width=6.5cm]{sin1.eps} \end{minipage}% }%注意这个”%”绝对不能省,可以试试不打%的效果 \begin{minipage}[c]{0.5\textwidth} \centering \includegraphics[width=6.5cm]{sin2.eps} \end{minipage} } \caption{fft}\label{fig:fft} \end{figure} 5、 其他细节可以详见开头说的那本书。还有关于图片的格式,如果用Latex编译的话只能用eps格式的图片,matlab就存为eps,其他用软件转吧,但是如果用Latex2pdf编译的话好像就能用jpg,eps反而不可以。但推荐使用eps,我试验下来matlab的图eps质量好,但好像不太支持中文,其实也有办法解决,我所知道的方法是用Psfrag宏包,详细方法还是参见那本书,但是我觉得用英文就行了嘛。 6、 其实真正的高手latex画图是这样画的,下面一段代码引自Arnold的一篇论文,可以运行一下,看看什么效果。 \begin{picture}(6,6) \thicklines \put(0,0){\line(1,1){6}} \put(0,6){\line(1,-1){3}} \put(1,1){\circle*{0.2}} \put(1,5){\circle*{0.2}} \put(5,5){\circle*{0.2}} \thinlines \multiput(1,1)(0,0.2){20}{\line(0,1){0.1}} \multiput(1,5)(0.2,0){20}{\line(1,0){0.1}} \put(1,5.2){\mbox{$A$}} \put(1,0.5){\mbox{$C$}} \put(4.5,5.2){\mbox{$B$}} \end{picture}