我使用以下方法导出matlab
了几个图tikz
matlab2tikz。其中许多都使用颜色,并且通常可以分组。然而,在 matlab 中为子图组添加一个颜色条并使用导出它似乎很困难matlab2tikz。我决定单独导出所有图,然后重新组合它们TeX
。这使我对图的子标题有了额外的控制权。
我现在正在努力对齐颜色条到不同子图的轴。我知道,使用 pgfplot 并仅从 matlab 导出数据可能会更容易。但是,由于时间有限且难以访问 matlab 文件,目前这不是一个选项。
我想要实现的目标:将颜色条左侧与第一个子图的 y 轴对齐。将颜色条右侧与第二个子图的右侧 y 轴对齐在其他图中,将颜色条放在图的右侧也会出现类似的问题(我的印象是,由于子图包的排列,这可能不是完全相同的问题。)如果你们有建议如何将子标题置于中央在子图的 y 标签下方,我会很高兴。您会发现附加了 MWE,图中的颜色被忽略了,数据也是如此。提前致谢!
\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{tikz}
\usepackage{pgfplots}
\newlength{\plotwidth}
\newlength{\plotheight}
\newlength{\xlabelwidth}
\newlength{\ylabelwidth}
\begin{document}
\begin{figure}[ptb]
\begin{small}
\begin{subfigure}[t]{1.0\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}[
hide axis,
scale only axis,
height=0pt,
width=0pt,
colormap/jet,
colorbar horizontal,
point meta min=0,
point meta max=30,
colorbar style={
width=10cm,
xtick={0,5,...,30},
ylabel style={},
xticklabel pos=upper
},
title style={xshift=4.7cm},
title={Symbol4}]
\addplot [draw=none] coordinates {(0,0)};
\end{axis}
\end{tikzpicture}
\end{subfigure}
\begin{tabular}{c c}
\setlength{\plotwidth}{0.48\textwidth}
\setlength{\plotheight}{0.3\textwidth}
\setlength{\xlabelwidth}{10em}
\setlength{\ylabelwidth}{2.5em}
\begin{subfigure}[t]{0.5\textwidth}
\vspace*{0.25cm}
\centering
\begin{tikzpicture}
\begin{axis}[width=\plotwidth,
height=\plotheight,
xlabel=Symbol1,
ylabel=Symbol2,yticklabel style={text width=\ylabelwidth,align=right},xticklabel style={text width=\xlabelwidth,align=center},tick label style={/pgf/number format/fixed}]
\addplot[color=red,mark=x] coordinates {
(2,-2.8559703)
(3,-3.5301677)
(4,-4.3050655)
(5,-5.1413136)
(6,-6.0322865)
(7,-6.9675052)
(8,-7.9377747)
};
\end{axis}
\end{tikzpicture}
\caption{Data 1}
\end{subfigure} &
\setlength{\plotwidth}{0.48\textwidth}
\setlength{\plotheight}{0.3\textwidth}
\setlength{\xlabelwidth}{10em}
\setlength{\ylabelwidth}{2.5em}
\begin{subfigure}[t]{0.5\textwidth}
\vspace*{0.25cm}
\centering
\begin{tikzpicture}
\begin{axis}[width=\plotwidth,
height=\plotheight,
xlabel=Symbol1,
ylabel=Symbol2,yticklabel style={text width=\ylabelwidth,align=right},xticklabel style={text width=\xlabelwidth,align=center},tick label style={/pgf/number format/fixed}]
\addplot[color=red,mark=x] coordinates {
(2,-2.8559703)
(3,-3.5301677)
(4,-4.3050655)
(5,-5.1413136)
(6,-6.0322865)
(7,-6.9675052)
(8,-7.9377747)
};
\end{axis}
\end{tikzpicture}
\caption{Data 2}
\end{subfigure} \\
\setlength{\plotwidth}{0.48\textwidth}
\setlength{\plotheight}{0.3\textwidth}
\setlength{\xlabelwidth}{10em}
\setlength{\ylabelwidth}{2.5em}
\begin{subfigure}[t]{0.5\textwidth}
\vspace*{0.25cm}
\centering
\begin{tikzpicture}
\begin{axis}[width=\plotwidth,
height=\plotheight,
xlabel=Symbol1,
ylabel=Symbol2,yticklabel style={text width=\ylabelwidth,align=right},xticklabel style={text width=\xlabelwidth,align=center},tick label style={/pgf/number format/fixed}]
\addplot[color=red,mark=x] coordinates {
(2,-2.8559703)
(3,-3.5301677)
(4,-4.3050655)
(5,-5.1413136)
(6,-6.0322865)
(7,-6.9675052)
(8,-7.9377747)
};
\end{axis}
\end{tikzpicture}
\caption{Data 3}
\end{subfigure} &
\setlength{\plotwidth}{0.48\textwidth}
\setlength{\plotheight}{0.3\textwidth}
\setlength{\xlabelwidth}{10em}
\setlength{\ylabelwidth}{2.5em}
\begin{subfigure}[t]{0.5\textwidth}
\vspace*{0.25cm}
\centering
\begin{tikzpicture}
\begin{axis}[width=\plotwidth,
height=\plotheight,
xlabel=Symbol1,
ylabel=Symbol2,yticklabel style={text width=\ylabelwidth,align=right},xticklabel style={text width=\xlabelwidth,align=center},tick label style={/pgf/number format/fixed}]
\addplot[color=red,mark=x] coordinates {
(2,-2.8559703)
(3,-3.5301677)
(4,-4.3050655)
(5,-5.1413136)
(6,-6.0322865)
(7,-6.9675052)
(8,-7.9377747)
};
\end{axis}
\end{tikzpicture}
\caption{Data 4}
\end{subfigure} \\
\end{tabular}
\end{small}
\caption{My data}
\end{figure}
\end{document}
答案1
您可以手动设置位置at={(0.252,0.0)},anchor=north west,
和宽度width=11.156cm,
(尝试并出错)。您还必须删除%height=0pt, %width=0pt,
。
梅威瑟:
\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{tikz}
\usepackage{pgfplots}
\newlength{\plotwidth}
\newlength{\plotheight}
\newlength{\xlabelwidth}
\newlength{\ylabelwidth}
\begin{document}
\begin{figure}[ptb]
\begin{small}
\begin{subfigure}[t]{1.0\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}[
hide axis,
scale only axis,
%height=0pt,
%width=0pt,
colormap/jet,
colorbar horizontal,
point meta min=0,
point meta max=30,
colorbar style={
width=11.156cm,
xtick={0,5,...,30},
ylabel style={},
xticklabel pos=upper,
at={(0.252,0.0)},anchor=north west,
title={Symbol4},
title style={xshift=0cm}
}
]
\addplot[draw=none] coordinates {(0,0)};
\end{axis}
\end{tikzpicture}
\end{subfigure}
\begin{tabular}{c c}
\setlength{\plotwidth}{0.48\textwidth}
\setlength{\plotheight}{0.3\textwidth}
\setlength{\xlabelwidth}{10em}
\setlength{\ylabelwidth}{2.5em}
\begin{subfigure}[t]{0.5\textwidth}
\vspace*{0.25cm}
\centering
\begin{tikzpicture}
\begin{axis}[width=\plotwidth,
height=\plotheight,
xlabel=Symbol1,
ylabel=Symbol2,yticklabel style={text width=\ylabelwidth,align=right},xticklabel style={text width=\xlabelwidth,align=center},tick label style={/pgf/number format/fixed}]
\addplot[color=red,mark=x] coordinates {
(2,-2.8559703)
(3,-3.5301677)
(4,-4.3050655)
(5,-5.1413136)
(6,-6.0322865)
(7,-6.9675052)
(8,-7.9377747)
};
\end{axis}
\end{tikzpicture}
\caption{Data 1}
\end{subfigure} &
\setlength{\plotwidth}{0.48\textwidth}
\setlength{\plotheight}{0.3\textwidth}
\setlength{\xlabelwidth}{10em}
\setlength{\ylabelwidth}{2.5em}
\begin{subfigure}[t]{0.5\textwidth}
\vspace*{0.25cm}
\centering
\begin{tikzpicture}
\begin{axis}[width=\plotwidth,
height=\plotheight,
xlabel=Symbol1,
ylabel=Symbol2,yticklabel style={text width=\ylabelwidth,align=right},xticklabel style={text width=\xlabelwidth,align=center},tick label style={/pgf/number format/fixed}]
\addplot[color=red,mark=x] coordinates {
(2,-2.8559703)
(3,-3.5301677)
(4,-4.3050655)
(5,-5.1413136)
(6,-6.0322865)
(7,-6.9675052)
(8,-7.9377747)
};
\end{axis}
\end{tikzpicture}
\caption{Data 2}
\end{subfigure} \\
\setlength{\plotwidth}{0.48\textwidth}
\setlength{\plotheight}{0.3\textwidth}
\setlength{\xlabelwidth}{10em}
\setlength{\ylabelwidth}{2.5em}
\begin{subfigure}[t]{0.5\textwidth}
\vspace*{0.25cm}
\centering
\begin{tikzpicture}
\begin{axis}[width=\plotwidth,
height=\plotheight,
xlabel=Symbol1,
ylabel=Symbol2,yticklabel style={text width=\ylabelwidth,align=right},xticklabel style={text width=\xlabelwidth,align=center},tick label style={/pgf/number format/fixed}]
\addplot[color=red,mark=x] coordinates {
(2,-2.8559703)
(3,-3.5301677)
(4,-4.3050655)
(5,-5.1413136)
(6,-6.0322865)
(7,-6.9675052)
(8,-7.9377747)
};
\end{axis}
\end{tikzpicture}
\caption{Data 3}
\end{subfigure} &
\setlength{\plotwidth}{0.48\textwidth}
\setlength{\plotheight}{0.3\textwidth}
\setlength{\xlabelwidth}{10em}
\setlength{\ylabelwidth}{2.5em}
\begin{subfigure}[t]{0.5\textwidth}
\vspace*{0.25cm}
\centering
\begin{tikzpicture}
\begin{axis}[width=\plotwidth,
height=\plotheight,
xlabel=Symbol1,
ylabel=Symbol2,yticklabel style={text width=\ylabelwidth,align=right},xticklabel style={text width=\xlabelwidth,align=center},tick label style={/pgf/number format/fixed}]
\addplot[color=red,mark=x] coordinates {
(2,-2.8559703)
(3,-3.5301677)
(4,-4.3050655)
(5,-5.1413136)
(6,-6.0322865)
(7,-6.9675052)
(8,-7.9377747)
};
\end{axis}
\end{tikzpicture}
\caption{Data 4}
\end{subfigure} \\
\end{tabular}
\end{small}
\caption{My data}
\end{figure}
\end{document}