\documentclass{article}
\usepackage{pgfplotstable}
\title {Hydrogen Breath Test Report}
\begin{document}
\maketitle
\begin{tikzpicture}
\begin{axis}[
xlabel=min,
ylabel=Hydrogen ppm]
\addplot[color=black,mark=x] coordinates {
(0, 2)
(15,4)
(30, 15)
(60, 20)
(90, 25)
(120, 30)
(180, 45)
};
\addplot[color=black!10] coordinates{
(0, 13)
(15,13)
(30, 13)
(60, 13)
(90, 13)
(120, 13)
(180, 13)
};
\end{axis}
\end{tikzpicture}
\end{document}
你好,请看一下这段代码。我画了一条灰色的水平线来表示截止水平。有没有更好的方法?x 轴上的“0”是基线值。我怎样才能用“基线”标签代替“0”?问候
答案1
所以这可能是您正在寻找的内容...
(有关更多详细信息,请查看代码的注释。)
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{
% to place the axis labels better
compat=1.3,
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
% define the axis limits
xmin=0,
xmax=200,
ymin=0,
ymax=50,
% improved a bit the axis labels
xlabel=time in min,
ylabel=Hydrogen concentration in ppm,
% -----------------------------
% add extra labels at x = 0 and y = 13
extra x ticks={0},
extra y ticks={13},
% define the style for the extra ticks
extra tick style={
% to not draw an extra tick set the width to 0
tickwidth=0pt,
% write "baseline" as extra x tick label
xticklabels={baseline},
% so the 0 of the normal ticks isn't seen any more ...
xticklabel style={
% ... fill the extra tick label white ...
fill=white,
% ... and adjust the "sep"s of the node so the 0 of the
% y tick label isn't overdrawn
% to do so just exchange the default values of the inner
% and outer sep
inner sep=0pt,
outer sep=0.3333em,
},
% to not draw an extra y tick label give an empty argument
yticklabels={},
% instead a grid line should be drawn
ymajorgrids=true,
},
]
\addplot [mark=x] coordinates {
( 0, 2)
( 15, 4)
( 30, 15)
( 60, 20)
( 90, 25)
(120, 30)
(180, 45)
};
\end{axis}
\end{tikzpicture}
\end{document}