我有以下代码:
\documentclass[12pt,a4paper]{article}
\newcounter{conto}
\setcounter{conto}{\time}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{url}
\usepackage{amssymb}
\usepackage{ dsfont }
\usepackage[mathscr]{euscript}
\usepackage{booktabs}
\newcommand{\longto}{\longrightarrow}
\usepackage{mathrsfs}
\usepackage{amsmath}
\usepackage{graphicx}
\newcommand*{\Scale}[2][4]{\scalebox{#1}{$#2$}}%
\newcommand*{\Resize}[2]{\resizebox{#1}{!}{$#2$}}%
\renewcommand{\figurename}{Graph}
\pagestyle{empty}
\usepackage{pgfplots}
\pgfmathdeclarefunction{gauss}{2}{%
\pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
\usepackage{eurosym}
\begin{document}
\begin{tikzpicture}
\begin{axis}[every axis plot post/.append style={
mark=none,samples=50,smooth},
axis x line=bottom,
axis y line=left,
axis x line=middle,
xlabel={\(a \in \mathbf{Set}(\{\mathbf{mis}_i(X)\}_{i=1}^6 )\)},
ylabel={\(f_a^{\text{rel}}\)},
axis y line=middle,
xlabel={\(x\)},
ylabel={\(\mathcal{G}_{u,p}(x)\)},
every axis x label/.style={mark=none,smooth,
at={(ticklabel* cs:1.05)},
anchor=west,},
every axis y label/.style={mark=none,smooth,
at={(ticklabel* cs:1.05)},
anchor=south,},
xtick={-3,-2,-1,0,1,2,3,4,5},
ytick={0,0.2,0.4,0.6,0.8,1.0},
enlargelimits=upper] % extend the axes a bit to the right and top
\addplot {gauss(0,0.5)};
\addplot {gauss(1,0.75)};
\end{axis}
\end{tikzpicture}
\end{document}
但输出是:
我怎样才能获得输出:
?? 提前致谢!
答案1
您可以添加extra description
以添加缺失的描述。
缺失的 x 刻度标签实际上是 pgfplots 的一个功能:它试图隐藏可能被遮挡的刻度标签。当前不稳定版本中已经实现了一项功能来重新启用这些刻度标签。
两个“一刻度距离”条可以通过自定义 TikZ 指令放置。我希望我理解了你的意图。我尝试在以下示例中解决它:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfmathdeclarefunction{gauss}{2}{%
\pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}
\pgfplotsset{compat=1.10}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
every axis plot post/.append style={
mark=none,samples=50,smooth
},
axis x line=bottom,
axis y line=left,
axis x line=middle,
xlabel={\(a \in \mathbf{Set}(\{\mathbf{mis}_i(X)\}_{i=1}^6 )\)},
ylabel={\(f_a^{\text{rel}}\)},
axis y line=middle,
xlabel={\(x\)},
ylabel={\(\mathcal{G}_{u,p}(x)\)},
every axis x label/.style={mark=none,smooth,
at={(ticklabel* cs:1.05)},
anchor=west,
},
every axis y label/.style={
mark=none,smooth,
at={(ticklabel* cs:1.05)},
anchor=south,
},
xtick={-3,-2,-1,0,1,2,3,4,5},
ytick={0,0.2,0.4,0.6,0.8,1.0},
%
% will become part of pgfplots 1.11 (is already in developer version):
%hide obscured x ticks=false,
extra description/.append code={%
%
% pgfplots up to (and including) 1.10 omits tick labels at the
% intersection of axes. We place it manually: the 0.15cm is
% the default length of tick lines:
\node[anchor=north,yshift=-0.15cm/2] at (axis cs:0,0) {$0$};
%
% the following uses tikz drawing instructions with pgfplots
% placement options:
% (rel axis cs:<x percent>,<y percent>) places relative to the axis size
% (axis direction cs:<x units>,<y units>) is to be used to *increments* (only)
% '++' advances the "last point" by the following one:
\draw[|-|] (rel axis cs:0.8,0.5) -- ++ (axis direction cs:1,0) node[anchor=west] {$=1$};
%
\draw[|-|] (rel axis cs:0.8,0.55) ++ (axis direction cs:0.5,0) -- ++ (axis direction cs:0,0.2) node[pos=0.5,anchor=west] {$=0.2$};
%
% instead of (rel axis cs:..) ++ (axis direction cs:...) one
% could also provide absolute coordinates of the form (axis cs:<x coord>,<y coord>)
},
enlargelimits=upper] % extend the axes a bit to the right and top
\addplot {gauss(0,0.5)};
\addplot {gauss(1,0.75)};
\end{axis}
\end{tikzpicture}
\end{document}
我已添加内嵌评论作为解释。
如果您想要一个描述红色/蓝色曲线的图例,请考虑使用legend entries={...}
图例。