我正在处理一堆图和组图,有时会发生一些奇怪的事情。我正在根据数据表进行绘图,当需要确定 y 刻度距离时,有时科学符号“位置合适”(至少对于我个人的需求而言),有时则不是。这里有两张图片:
如您所见,第一幅图将10^-2
右侧放在顶部,而第二幅图代表了我想指出的“问题”。有没有办法强制科学符号留在图表顶部?我不明白算法如何决定放置符号。
下面是我当前正在使用的 groupplot 结构:
\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{pgf,pgfplots,pgfplotstable}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{colormaps}
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{figure}[htbp]
\centering
\pgfplotstableread{data/v3/b1/vel/vzt.dat}{\DataTableA}
\pgfplotstableread{data/v3/b2/vel/vzt.dat}{\DataTableB}
\begin{tikzpicture}[scale=0.9]
\begin{groupplot}[group style={
group name=vztcompcross,
group size=1 by 2,
xlabels at=edge bottom,
ylabels at=edge left,
vertical sep=4em
},
xmin = 0, xmax = 30,
ymin = -0.09, ymax = 0.06,
xtick distance = 5,
ytick distance = 0.03,
xlabel={$time\;[s]$},
ylabel={$V_z\;[km/s]$},
grid = both,
grid style = {dotted},
minor tick num = 1,
major grid style = {lightgray!75},
minor grid style = {lightgray!75},
width = 0.85\textwidth,
height = 0.50\textwidth,
%scale only axis,
%legend cell align = {left},
%legend pos = north east,
legend style={at={(0.5,-0.3)},
anchor=north,legend columns=4},
legend cell align = {left},
]
\nextgroupplot[title={title1}]
\addplot[smooth, black, ultra thick] table [x = {t1a}, y = {vz1a}] {\DataTableA};
\addplot[smooth, Lavender, very thick] table [x = {t1b}, y = {vz1b}] {\DataTableA};
\addplot[smooth, Violet, very thick] table [x = {t1c}, y = {vz1c}] {\DataTableA};
\addplot[smooth, Emerald, dotted, ultra thick] table [x = {t2}, y = {vz2}] {\DataTableA};
\nextgroupplot[title={title2},
xmin = 0, xmax = 15,
ymin = -0.12, ymax = 0.06,
ytick distance = 0.03,
legend entries={n1(k),n1(k-2),n1(k-4),n2(k),n2(j),n2(j+1.5),n2(j+3)},
]
\addlegendimage{black, no markers, very thick}
\addlegendimage{Lavender, no markers, very thick}
\addlegendimage{Violet, no markers, very thick}
\addlegendimage{Emerald, dotted, no markers, ultra thick}
\addlegendimage{Apricot, no markers, very thick}
\addlegendimage{RedOrange, no markers, very thick}
\addlegendimage{MidnightBlue, no markers, very thick}
\addplot[smooth, Apricot, ultra thick] table [x = {t1a}, y = {vz1a}] {\DataTableB};
\addplot[smooth, RedOrange, very thick] table [x = {t1b}, y = {vz1b}] {\DataTableB};
\addplot[smooth, MidnightBlue, very thick] table [x = {t1c}, y = {vz1c}] {\DataTableB};
\end{groupplot}
\end{tikzpicture}
\caption{some random caption}
\end{figure}
\end{document}
答案1
好的,我刚刚制作了一些虚拟表来试用您的代码。您需要添加的唯一一行是scaled y ticks = base x:y
。对于DataTableB
,在这种情况下,您必须手动传递scaled y ticks = base 10:2
,然后强制-0.12
显示为,-12
从而允许使用公因数进行缩放。我注释掉了导致无法编译或不需要给出解决方案的行。
\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{pgf,pgfplots,pgfplotstable}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{colormaps}
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{figure}[htbp]
\centering
\pgfplotstableread{table.txt}{\DataTableA}
\pgfplotstableread{table.txt}{\DataTableB}
\begin{tikzpicture}[scale=0.9]
\begin{groupplot}[group style={
group name=vztcompcross,
group size=1 by 2,
xlabels at=edge bottom,
ylabels at=edge left,
vertical sep=4em
},
xmin = 0, xmax = 30,
ymin = -0.09, ymax = 0.06,
xtick distance = 5,
ytick distance = 0.03,
xlabel={$time\;[s]$},
ylabel={$V_z\;[km/s]$},
grid = both,
grid style = {dotted},
minor tick num = 1,
major grid style = {lightgray!75},
minor grid style = {lightgray!75},
width = 0.85\textwidth,
height = 0.50\textwidth,
%scale only axis,
%legend cell align = {left},
%legend pos = north east,
legend style={at={(0.5,-0.3)},
anchor=north,legend columns=4},
legend cell align = {left},
scaled ticks=true
]
\nextgroupplot[title={title1}]
\addplot[smooth, black, ultra thick] table [x = {t1a}, y = {vz1a}] {\DataTableA};
%\addplot[smooth, Lavender, very thick] table [x = {t1b}, y = {vz1b}] {\DataTableA};
%\addplot[smooth, Violet, very thick] table [x = {t1c}, y = {vz1c}] {\DataTableA};
%\addplot[smooth, Emerald, dotted, ultra thick] table [x = {t2}, y = {vz2}] {\DataTableA};
\nextgroupplot[
scaled y ticks=base 10:2 %<----------- Here
title={title2},
xmin = 0, xmax = 15,
ymin = -0.12, ymax = 0.06,
ytick distance = 0.03,
% legend entries={n1(k),n1(k-2),n1(k-4),n2(k),n2(j),n2(j+1.5),n2(j+3)},
]
% \addlegendimage{black, no markers, very thick}
% \addlegendimage{Lavender, no markers, very thick}
% \addlegendimage{Violet, no markers, very thick}
% \addlegendimage{Emerald, dotted, no markers, ultra thick}
% \addlegendimage{Apricot, no markers, very thick}
% \addlegendimage{RedOrange, no markers, very thick}
% \addlegendimage{MidnightBlue, no markers, very thick}
%
%
\addplot[smooth, Apricot, ultra thick] table [x = {t1a}, y = {vz1a}] {\DataTableB};
% \addplot[smooth, RedOrange, very thick] table [x = {t1b}, y = {vz1b}] {\DataTableB};
% \addplot[smooth, MidnightBlue, very thick] table [x = {t1c}, y = {vz1c}] {\DataTableB};
%
%
%
%
\end{groupplot}
\end{tikzpicture}
\caption{some random caption}
\end{figure}
\end{document}
通过设置scaled y ticks=base 10:1
,您可以获得