21

I am using pgfplots to plot the a function. I have been looking around on the forums, but I could not find a solution. I would like to origin to be indicated as a 0 on the x axis. I would also like to get the axis labels to appear respectively left and below the axis. Any ideas?

I have the following plot:

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[width=7cm, height=2cm,xmin=-6,xmax=6,ymin=0,ymax=1,
no markers,
samples=50,
axis lines=left, 
axis lines=middle, 
scale only axis,
% extra y ticks={0.5},
/pgfplots/ytick={0, 0.5,1}, % make steps of length 0.5
/pgfplots/xtick={-5,0,5}, % make steps of length 5
    xlabel=$Li$,
    ylabel={$f_{comp}(Li))$}
  ] 
    \addplot {1/(1+exp(-x)}; 
  \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

lockstep
  • 250,273
dorien
  • 1,615

1 Answers1

24

The middle option for the axis lines assumes that the axis lines intersect, so the 0 ticks aren't shown. If you use axis y line=middle, axis x line=bottom instead of axis lines=middle, you get the desired tick mark:

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    width=7cm, height=2cm,xmin=-6,xmax=6,ymin=0,ymax=1,
    no markers,
    samples=50,
    axis y line=middle, 
    axis x line=bottom,
    scale only axis,
    ytick={0, 0.5,1}, % make steps of length 0.5
    xtick={-5,0,5}, % make steps of length 5
    xlabel=$Li$,
    ylabel={$f_{comp}(Li))$}
  ] 
    \addplot {1/(1+exp(-x)}; 
  \end{axis}
\end{tikzpicture}
\end{document}
Jake
  • 232,450
  • 1
    Thanks! Combined withevery axis x label/.style={at={(current axis.right of origin)},anchor=north west}, every axis y label/.style={at={(current axis.above origin)},anchor=north east},... I got a perfect result! – dorien Oct 23 '12 at 13:23
  • 2
    What could I do, if I wanted to keep both axes as middle (so they intersect) and print the zero labels on top of them? Would that be possible? – sdaau Feb 15 '14 at 21:39
  • 1
    @sdaau: Take a look at http://tex.stackexchange.com/a/39099/2552 – Jake Feb 15 '14 at 21:48
  • Many, many thanks for that, @Jake - that answers it completely! Cheers! – sdaau Feb 15 '14 at 21:52
  • What if the graph has negative y-values? – minseong Sep 21 '17 at 10:20
  • @theonlygusti: See https://tex.stackexchange.com/questions/39098/need-to-do-some-changes-to-pgfplots-axis – Jake Sep 21 '17 at 10:56