在科研论文写作中,有时候为了横向、纵向对比或者节省空间,我们需要画子图,在MATLAB中可以通过subplot命令来实现。在Latex中有以下几种方法进行子图的绘制:
- 使用subfig宏包(有可能与hyperref宏包冲突,推荐使用subcaption宏包),主要格式为:

  \begin{figure}\subfloat[]{}\subfloat[]{}\\\subfloat[]{}\subfloat[]{}\end{figure}
  • 使用subcaption宏包,主要格式为:
  \begin{figure}\subcaptionbox{}{}\subcaptionbox{}{}\\\subcaptionbox{}{}\subcaptionbox{}{}\end{figure}
  • 使用groupplot宏包,主要格式为:
  \begin{figure}
\centering
\begin{tikzpicture}
\begin{groupplot}
\nextgroupplot
\addplot {x};
\nextgroupplot
\end{groupplot}
\end{tikzpicture}
\end{figure}
  • 使用matrix宏包,主要格式为:
    \begin{figure}
\centering
\begin{tikzpicture}
\matrix{\begin{axis}\addplot {x};\end{axis}\begin{axis}\addplot {x};\end{axis}}
\end{tikzpicture}
\end{figure}

下面给出上述各种情况的具体代码实现以及示意图:
- 使用subfig宏包

代码如下:

\documentclass{article}
\usepackage[dvipdfm]{graphicx}
\def\pgfsysdriver{pgfsys-dvipdfmx.def}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{subfig}%使用子图包,可能与hyperref冲突
\usepackage{float}
\usepackage{cite}
\usepackage[colorlinks,dvipdfm,pdfpagemode=UseOutlines,pdfstartview=FitH,anchorcolor=green,citecolor=blue,linkcolor=red,hyperindex=true,pagebackref,bookmarksnumbered,bookmarksopenlevel=2,colorlinks]{hyperref}\pgfplotsset{width=6cm,compat=1.15}\begin{document}
\begin{figure}
\begin{center}
\subfloat[\label{subfig1}]{
\begin{tikzpicture}
\begin{axis}[
legend columns=-1,%the legend are plotted horizontally
legend entries={$x$},
legend to name=named,% stored in named, not plotted in the figure
title={subfig1},
]
\addplot {x};\label{curvex}
\end{axis}
\end{tikzpicture}\label{subfig2}}
\subfloat[]{
\begin{tikzpicture}
\begin{axis}[title={subfig2}]
\addplot {x};
\end{axis}
\end{tikzpicture}\label{subfig2}}
\end{center}
\caption{\hspace{1em}Two subfigures.}\label{f1}
\end{figure}
As depicted in Figures~\ref{subfig1} and \ref{subfig2}, the subfigures of Figure~\ref{f1}, \ref{curvex} represents function $f(x)=x$.\end{document} 
  • 使用subcaption宏包

    代码如下:
\documentclass{article}
\usepackage[dvipdfm]{graphicx}
\def\pgfsysdriver{pgfsys-dvipdfmx.def}
\usepackage{tikz}
\usepackage{pgfplots}
%\usepackage{subfig}
\usepackage[hypcap=true,labelsep=period,font=small]{caption}% 图的标题设置Fig.
\usepackage[hypcap=true]{subcaption}%用于画子图 可以适配hyperref包
\usepackage{float}
\usepackage[colorlinks,dvipdfm,pdfpagemode=UseOutlines,pdfstartview=FitH,anchorcolor=green,citecolor=blue,linkcolor=red,hyperindex=true,pagebackref,bookmarksnumbered,bookmarksopenlevel=2,colorlinks]{hyperref}
\pgfplotsset{width=6cm,compat=1.15}
\begin{document}
\begin{figure}
\begin{center}
\subcaptionbox{\label{subfig1}}{
\begin{tikzpicture}
\begin{axis}[
legend columns=-1,%the legend are plotted horizontally
legend entries={$x$},
legend to name=named,% stored in named
title={subfig1},
]
\addplot {x};\label{curvex}
\end{axis}
\end{tikzpicture}}
\subcaptionbox{\label{subfig2}}{
\begin{tikzpicture}
\begin{axis}[title={subfig2}]
\addplot {x};
\end{axis}
\end{tikzpicture}}
\end{center}
\caption{\hspace{1em}Two subfigures.}\label{f1}
\end{figure}As depicted in Figures~\ref{subfig1} and \ref{subfig2}, the subfigures of Figure~\ref{f1}, \ref{curvex} represents function $f(x)=x$.\end{document} 
  • 使用groupplot宏包

    代码如下:
\documentclass{article}
\usepackage[dvipdfm]{graphicx}
\def\pgfsysdriver{pgfsys-dvipdfmx.def}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.15}
\usepgfplotslibrary{groupplots}
\usepackage{caption}
\usepackage{subcaption}
\usepackage[colorlinks,dvipdfm,pdfpagemode=UseOutlines,pdfstartview=FitH,anchorcolor=green,citecolor=blue,linkcolor=red,hyperindex=true,pagebackref,bookmarksnumbered,bookmarksopenlevel=2,colorlinks]{hyperref}
\begin{document}
\begin{figure}[htb]
\centering
\begin{tikzpicture}
\begin{groupplot}[
group style={group name=my plots,
group size=2 by 2,
xlabels at=edge bottom,
xlabels at=all,
ylabels at=edge left,
x descriptions at=edge bottom,
},
footnotesize,
width=6cm,
height=6cm,
%
xlabel=$x$,
ylabel=$f(x)$,
]
\nextgroupplot
\addplot {x};
\node [text width=1em,anchor=north west] at (rel axis cs: 0,1){\subcaption{\label{f11}}};%<- changed
\nextgroupplot
\addplot {x^2};
\nextgroupplot
\addplot {x^3};
\nextgroupplot
\addplot {x^4};
\end{groupplot}
\end{tikzpicture}
\caption{\hspace{1em}Four subfigures.}\label{f1}
\end{figure}
How to refer to subfigure~\ref{f11} in Figure~\ref{f1}.\end{document} 
  • 使用matrix宏包

    代码如下:
\documentclass{article}
\usepackage[dvipdfm]{graphicx}
\def\pgfsysdriver{pgfsys-dvipdfmx.def}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.15}
\usepgfplotslibrary{groupplots}
\usetikzlibrary{matrix}
\usepackage{caption}
\usepackage{subcaption}
\usepackage[colorlinks,dvipdfm,pdfpagemode=UseOutlines,pdfstartview=FitH,anchorcolor=green,citecolor=blue,linkcolor=red,hyperindex=true,pagebackref,bookmarksnumbered,bookmarksopenlevel=2,colorlinks]{hyperref}
\begin{document}
\begin{figure}[htb]
\centering
\begin{tikzpicture}
\pgfplotsset{small}
\matrix {\begin{axis}[ylabel={$f(x)=x$},ylabel style={font=\small}]
\addplot {x};
\node [text width=1em,anchor=north west] at (rel axis cs: 0,1){\subcaption{\label{f11}}};%<- changed
\end{axis}
&
% differently large labels are aligned automatically:
\begin{axis}[ylabel={$f(x)=x^2$},ylabel style={font=\small}]
\addplot {x^2};
\end{axis}
\\
\begin{axis}[ylabel={$f(x)=x^3$},ylabel style={font=\small},xlabel=$x$,xlabel style={font=\small}]
\addplot {x^3};
\end{axis}
&
\begin{axis}[ylabel={$f(x)=x^4$},ylabel style={font=\small},xlabel=$x$,xlabel style={font=\small}]
\addplot {x^4};
\end{axis}
\\
};
\end{tikzpicture}
\caption{\hspace{1em}Four subfigures.}\label{f1}
\end{figure}
How to refer to subfigure~\ref{f11} in Figure~\ref{f1}.\end{document} 

Note: 第三种和第四种方法不适合需要单独引用每一个子图的情况,比较适合把四张图看成一个整体的情况。


参考文献:
[1] pgfplots manual: http://pgfplots.sourceforge.net/pgfplots.pdf


本科舍友不幸得了黑色素癌, 在此恳求大家能给予帮助,在此谢谢大家!以下是水滴筹的链接:
https://www.shuidichou.com/cf/contribute/7d975cfc-e508-4549-acb1-5a31ceb759a1?channel=wx_charity_pyq&source=7hEPKZfbC7kzc7ndTKDD6cZriDdYH4TQ&forwardFrom=5&sharedv=2008
今天发现该链接已经提现了,但是已筹金额未达预期,期望各位通过左下角的微信扫码进行捐款,我将悉数给予舍友。再次感谢大家的帮助!

【漫漫科研路\pgfplots】子图的多种画法相关推荐

  1. 【漫漫科研路\pgfplots】多个子图共用一个图例

    十月底,投完会议之后,便对科研写作方面遇到的问题进行了探索.问题主要有: 问题: 文献管理问题:在写论文的过程中,经常要引用他人文献,这时需要费时去寻找.另一方面,有时想要查看曾经读到的某篇文章提到的 ...

  2. 【漫漫科研路\pgfplots】克服绘制色温图时,数据量大出现的内存限制

    在科研论文写作中,经常会遇到画色温图,3D图.此时一般输入的数据量比较大,导致在Latex中使用Tikz画图时出现内存不足的情况.常常报错如下: ! TeX capacity exceeded, so ...

  3. 【漫漫科研路\pgfplots】画局部放大图

    在科研论文写作中,我们经常需要放大局部图片来显示细节,即绘制图中图.在Matlab中可以使用magnify或则axes函数,网上有很多例子,这里不再赘述.本文主要讲解如何使用tikz/pgfplots ...

  4. 【漫漫科研路\PythonTikz】画神经网络相关图

    前一篇文章[图解例说机器学习]神经网络中,由于篇幅有限,我们只介绍了其理论部分.作为补充,本文主要介绍文中所有图像的绘制(使用Tikz或者Python).对于神经网络中的框架图 (例如神经元,神经网络 ...

  5. 【漫漫科研路\CC++】CPLEX解SOCP问题

    IBM CPLEX可以解SOCP问题,但是需要先将这个SOCP问题化为指定的格式.本文首先介绍SOCP问题,然后举例介绍如何将SOCP问题转化为CPLEX认可的输入格式并求解. SOCP的介绍 关于S ...

  6. 高文院士:从“乡村教师”到人工智能掌舵者的40年科研路

    成为一名工程师,是高文从小以来的梦想.在那个物质匮乏的年代,怀着对梦想的执着,高文从初中开始,便和周围的朋友一起玩无线电.摆弄收音机.凭借着这份单纯的执着,从哈尔滨工业大学计算机应用博士.东京大学电子 ...

  7. Linux那些事儿 之 戏说USB(2)漫漫辛酸路

    USB的一生充满了PK,并在PK中发展,1.0.1.1.2.0,漫漫辛酸路,一把辛酸泪. 这张表是从USB2.0 spec里直接拿过来的,可以看出,它的高速模式最高已经达到了480Mbps,即60MB ...

  8. 重磅直播|嵌入式开发漫漫之路—从小白到技术骨干

    点击上方"3D视觉工坊",选择"星标" 干货第一时间送达 大家好,本公众号现已开启线上视频公开课,主讲人通过B站直播间,对3D视觉领域相关知识点进行讲解,并在微 ...

  9. 兰艳艳:理想温暖10年科研路,女性可以柔和,更要自信、专业 | 妇女节特辑...

    她力量 近年来,"她"力量正在科学家群体中快速升温. 在一年一度的妇女节到来之际,智源社区选取了五位颇具代表性的女性科学家,进行了深度访谈.在她们中,有人选择食物图像识别,对选择的 ...

最新文章

  1. 【java线程】锁机制:synchronized、Lock、Condition
  2. 吴恩达深度学习笔记3-Course1-Week3【浅层神经网络】
  3. 这个云原生开发的痛点你遇到了吗?
  4. 单片机脉宽测量C语言,单片机脉宽测量的程序
  5. 其他系统 对外接口设计_外观模式:统一接口 VS.暴露细节
  6. linux 打印当前系统环境_Linux系统下搭建python环境
  7. linux中安装和配置 jdk
  8. 荣耀play3 鸿蒙,荣耀play系列跳过2直接上3代,999元的配置还能愉快play吗?
  9. python开源代码app_十个基于Python的BBS论坛类开源web框架汇总(附源码地址)
  10. C语言2级题pdf百度云,C语言二级考试试题.pdf
  11. 2018PS cc版本最新最实用学习笔记
  12. SOFTICE之后继有人——Syser
  13. 洛谷P2123 皇后游戏
  14. 使用unbound在RHEL7上搭建DNS服务
  15. 有关于取证的笔记——包含详细例题解析
  16. 微计算机应用是核心吗,北大核心哪个杂志好投
  17. 奋斗吧,程序员——第十六章 笑渐不闻声渐悄,多情却被无情恼
  18. 把你的面子撕下来扔到地上,狠狠踹几脚!
  19. 系统管理员设置了系统策略,禁止进行此安装。解决方案
  20. 用PhoneGap开发移动程序

热门文章

  1. 阿里云存储的视频大小和图片大小进行尺寸截取
  2. 关于泰勒展开的细节 三体 读后感的读后感
  3. AI时代 智慧家居的中心将是智能音箱
  4. 微信小程序 java音乐播放器系统uniapp
  5. Hive中 Oder by 、sort by、distribute by 和 cluster by
  6. JDBC insert delete update(DML)
  7. python的岗位多吗-为什么python的校招岗位这么少,校招python好找工作么?
  8. Broker主从同步详解
  9. 本地单机redis启动命令
  10. Android拨打、接听、挂断电话操作