我在尝试绘制一个简单的图表时收到了最奇怪的错误。让我给你演示一下 - 这是可行的:
\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\pgfplotsset{every axis plot post/.append style={line width=1.0pt}}
\pgfplotsset{grid style=dotted}
\begin{tikzpicture}
\begin{axis}
[clip marker paths=true,
legend pos= south east,
legend columns=1,
xlabel=time $T$ / s,
ylabel=losses $Q$ / J/cycle/m,
xmin=0, xmax=.02,
ymin=0, ymax=6e-2,
xtick={0,.005,.01,.015,.02},
%xticklabel style={/pgf/number format/.cd,sci}
%xticklabel={%
% \pgfmathfloatparsenumber{\tick}%
% \pgfmathfloatexp{\pgfmathresult}%
% \pgfmathprintnumber{\pgfmathresult}%
%}
]
\end{axis}
\end{tikzpicture}
\end{document}
但事实并非如此:
\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\pgfplotsset{every axis plot post/.append style={line width=1.0pt}}
\pgfplotsset{grid style=dotted}
\begin{tikzpicture}
\begin{axis}
[clip marker paths=true,
legend pos= south east,
legend columns=1,
xlabel=time $T$ / s,
ylabel=losses $Q$ / J/cycle/m,
xmin=0, xmax=.02,
ymin=0, ymax=6e-2,
xtick={0,.005,.01,.015,.02},
xticklabel style={/pgf/number format/.cd,sci}
%xticklabel={%
% \pgfmathfloatparsenumber{\tick}%
% \pgfmathfloatexp{\pgfmathresult}%
% \pgfmathprintnumber{\pgfmathresult}%
%}
]
\end{axis}
\end{tikzpicture}
\end{document}
知道原因吗?提前致谢
答案1
正如 Jake 所指出的,的最新版本pgfplots
与 不一样.cd
。对于旧版本(已测试 1.5),它工作正常。请参阅以下 MWE 以了解可能的修复方法。它还修复了 y 轴标签( )的重叠compat=1.8
:
\documentclass[tikz]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[sticky-per]{siunitx}
\listfiles %shows you the version of pgfplots and tikz (if of interest)
\usepackage{pgfplots}
\usepgfplotslibrary{units}
\pgfplotsset{
compat=1.8, %fixes y label position
every axis plot post/.append style={line width=1.0pt},
grid style=dotted,
unit marking pre={\!\!/}, %if you want to get the same appearance as in your MWE,
unit marking post={}, %you can change these two lines to "unit markings=slash space,"
}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
clip marker paths=true,
legend pos=south east,
legend columns=1,
xlabel=Time $t$, x unit=\si{\second},
ylabel=Losses $Q$, y unit=\si{(\joule\per cycle \meter}),
xmin=0, xmax=.02,
ymin=0, ymax=6e-2,
%scaled ticks=false, %if the new 1.8 ticks scaling is not desired
xtick={0,.005,.01,.015,.02},
xticklabel style={/pgf/number format/sci}, %changing this line removes the errors.
%More info about "Styles for ticks" can be seen in the pgfplots manual starting page 276
]
\end{axis}
\end{tikzpicture}
\end{document}