我对自己对 pgfplot 的理解不足感到非常沮丧,希望有人能帮助我弄清楚如何获得更易于阅读/理解的 x 轴刻度标记。我有以下内容:
但我希望 x 轴读起来更清晰,比如 2e-3 甚至 0.002,而不是 10^-2.6,这很难直观。我尝试使用“x 刻度标签”,但似乎对图没有任何影响!提前感谢您的帮助!
这是我用来创建图表的代码:
\documentclass[]{standalone}
\usepackage[utf8]{inputenc} % UTF8 encoding
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.6}
\begin{document}
\pgfplotsset{every axis plot}
\pgfplotsset{grid style=dotted}
\begin{tikzpicture}
\begin{loglogaxis}
[clip marker paths=true,legend cell align=left,
legend style={
at={(0.5,-0.2)},
anchor=north},
legend columns=2,
xlabel=field amplitude,
ylabel=losses,
xmin=2e-3, xmax=5e-2,
ymin=1e-4, ymax=1e-1,
grid=major
]
\addplot [sharp plot,mark=none, color=black,dotted] table[skip first n=2,x expr=\thisrow{x},y expr=\thisrow{y}]
{Comp_DataSim.eins.table};
\end{loglogaxis}
\end{tikzpicture}
\end{document}
我把数据上传到这里: http://pastebin.com/1zzgtQ2f
答案1
您可以尝试使用pgf/number format/
手册中描述的关键来pgfplotstable
实现各种结果。
两个例子:
\documentclass[]{standalone}
\usepackage[utf8]{inputenc} % UTF8 encoding
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.6}
\begin{document}
\pgfplotsset{every axis plot}
\pgfplotsset{grid style=dotted}
\begin{tikzpicture}
\begin{loglogaxis}
[clip marker paths=true,legend cell align=left,
legend style={
at={(0.5,-0.2)},
anchor=north},
legend columns=2,
xlabel=field amplitude,
ylabel=losses,
xmin=2e-3, xmax=5e-2,
ymin=1e-4, ymax=1e-1,
xtick={2e-3,5e-3,1e-2,2e-2,5e-2},
xticklabel style={/pgf/number format/.cd,fixed,precision=3},
xticklabel={%
\pgfmathfloatparsenumber{\tick}%
\pgfmathfloatexp{\pgfmathresult}%
\pgfmathprintnumber{\pgfmathresult}%
},
grid=major
]
% Below is a dummy plot so that the MWE is self-contained
% Anyway, only the axes matter, right? :-)
\addplot+ coordinates
{(0,1)
(5,2)
(10,3)
(50,4)
(100,5)
(500,6)
(1000,7)
(5000,8)
(10000,9)
(100000,10)}
;
\end{loglogaxis}
\end{tikzpicture}
\end{document}
\documentclass[]{standalone}
\usepackage[utf8]{inputenc} % UTF8 encoding
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.6}
\begin{document}
\pgfplotsset{every axis plot}
\pgfplotsset{grid style=dotted}
\begin{tikzpicture}
\begin{loglogaxis}
[clip marker paths=true,legend cell align=left,
legend style={
at={(0.5,-0.2)},
anchor=north},
legend columns=2,
xlabel=field amplitude,
ylabel=losses,
xmin=2e-3, xmax=5e-2,
ymin=1e-4, ymax=1e-1,
xtick={2e-3,5e-3,1e-2,2e-2,5e-2},
xticklabel style={/pgf/number format/sci},
xticklabel={%
\pgfmathfloatparsenumber{\tick}%
\pgfmathfloatexp{\pgfmathresult}%
\pgfmathprintnumber{\pgfmathresult}%
},
grid=major
]
\addplot+ coordinates
{(0,1)
(5,2)
(10,3)
(50,4)
(100,5)
(500,6)
(1000,7)
(5000,8)
(10000,9)
(100000,10)}
;
\end{loglogaxis}
\end{tikzpicture}
\end{document}