1

The below picture is what I have currently: what I want is to change 4 to a and 6 to b; but, if I change one of them using the xticklabel option it globally changes all x-values to that value. There's also the issue of the xtick height; if you see below, it goes way above the normal distribution--I tried some of the options in the "Tick-Fine Tuning" section in the manual, but they didn't work for me. I'm also trying to remove the y-axis: one thing I tried is messing around with the axis lines*=left option; however I wasn't able to come up with the result I wanted.

enter image description here

\documentclass{article}
\usepackage{pgfplots}
\begin{document}

\pgfmathdeclarefunction{gauss}{2}{%
  \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}

\begin{tikzpicture}
\begin{axis}[
  no markers, domain=0:10, samples=100,
  axis lines*=left,
  every axis y label/.style={at=(current axis.above origin),anchor=south},
  every axis x label/.style={at=(current axis.right of origin),anchor=west},
  height=3cm, width=6cm, 
  xtick={4, 6}, ytick=\empty,
  enlargelimits=false, clip=false, axis on top,
  grid = major
  ]
  \addplot [fill=cyan!20, draw=none, domain=4:6] {gauss(5,1)} \closedcycle;
  \addplot [very thick,cyan!50!black] {gauss(5,1)};

\end{axis}

\end{tikzpicture}
\end{document}

Furthermore, I would also like to have another normal distribution in the same row: I don't know how to go about doing that.

5
  • Please limit your posts to one question per post, I provide an answer to the question about changing the x tick label from 4 to a etc. Apr 27 at 2:22
  • Thanks for the good MWE (but you can remove several of the options for the question). Apr 27 at 2:28
  • 1
    About removing the y axis, there are several related question, see tex.stackexchange.com/questions/296325 (axis y line=none) for example (I googled pgfplots remove y axis). Apr 27 at 2:39
  • I also removed for normal distribution from your title because it is irrelevant to the question. Apr 27 at 2:41
  • Thank you for the help that related question solved the y-axis removal for me. @Dr.ManuelKuehner Apr 27 at 2:48

1 Answer 1

2
  • Using xticklabels = {\strut a, \strut b}, leads to the following output (see also the two comments in the code). You can use $a$ instead of a if that is more appropriate for your use case.
  • You have to be careful, there is an option called xticklabel and another one called xticklabels (with "s").
  • This caused confusion for myself in the past :).

enter image description here

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18} % <-- ADDED, see Warning Message "Package pgfplots Warning: running in backwards compatibility mode (unsuitable tick labels; missing features). Consider writing \pgfplotsset{compat=1.18} into your preamble."
\begin{document}

\pgfmathdeclarefunction{gauss}{2}{%
  \pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}

\begin{tikzpicture}
\begin{axis}[
  no markers, 
  domain=0:10, 
  samples=100,
  axis lines*=left,
  every axis y label/.style={at=(current axis.above origin),anchor=south},
  every axis x label/.style={at=(current axis.right of origin),anchor=west},
  height=3cm, 
  width=6cm, 
  xtick={4, 6}, 
  xticklabels = {\strut a, \strut b}, % <-- ADDED, the \strut makes that both labels have the same height
  ytick=\empty,
  enlargelimits=false, 
  clip=false, 
  axis on top,
  grid = major,
  ]
  \addplot [fill=cyan!20, draw=none, domain=4:6] {gauss(5,1)} \closedcycle;
  \addplot [very thick,cyan!50!black] {gauss(5,1)};
\end{axis}

\end{tikzpicture}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.