# How can I make logarithmic axes through the origin?

I have this graph: The x-axis looks like it should look like:

• arrow head at its end
• label near the arrow head
• it goes through the origin

But the y-axis does strange things:

• It does not go through the origin
• no arrow head
• it is at the end of the arrow head of the x-axis.

I don't need the y-axis to go exactly at through origin, but it should be at the left side of the plot. Also it would be nice if the line of the y-axis was a little bit longer than [-1, 1], e.g. [-1.2, 1.2].

How can I change to y-axis to look look like this?

Here is the LaTeX-Code:

\documentclass{article}
\usepackage[pdftex,active,tightpage]{preview}
\setlength\PreviewBorder{2mm}

\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{arrows, positioning, calc}

\begin{document}
\begin{preview}

\begin{tikzpicture}
\begin{axis}[
axis x line=middle,
xmode=log, % Logarithmic x axis
xmin=0.01, xmax=1, % Positive domain...
xticklabel=\pgfmathparse{exp(\tick)}\pgfmathprintnumber{\pgfmathresult},
xticklabel style={/pgf/number format/.cd,fixed}, % Use fixed point notation
width=15cm, height=8cm,     % size of the image
grid = major,
grid style={dashed, gray!30},
ymin=-1,      % start the diagram at this y-coordinate
ymax= 1,      % end   the diagram at this y-coordinate
axis background/.style={fill=white},
ylabel=y,
xlabel=x,
legend style={at={(0.9,0.95)}, anchor=north}
]
\addplot[domain=0.01:1, red, thick,samples=2000] {-sin(deg(1/(x)))};
\legend{$\sin(\frac{1}{x})$}
\end{axis}
\end{tikzpicture}
\end{preview}
\end{document}

• The y axis is still set to its default (vertical lines at the left and right edge of the plot), while you changed the x axis style to middle. If you set axis y line=left, you'll get the y axis at the left edge of the plot. Is that what you're trying to get? For making the axis a bit longer, you can set enlarge y limits=true. – Jake Sep 22 '12 at 12:59
• Thanks Jake! That was exactly what I was looking for. Where is something like axis y line=left documented? I know the PGF Manual (I've searched the pdf for axis y line), but I didn't find possible values for axis y line. Most of the time when I try to solve something like this, I search for examples (and I publish my examples on github for others who are searching for examples). – Martin Thoma Sep 22 '12 at 13:55
• It's documented in the PGFPlots manual. PGFPlots is a package that's separate from PGF (although it builds on it). – Jake Sep 22 '12 at 13:57
• @Jake why don't you turn your comment(s) into an answer? – Gonzalo Medina Sep 24 '12 at 2:39

## 1 Answer

The y axis is still set to its default (vertical lines at the left and right edge of the plot), while you changed the x axis style to middle. If you set axis y line=left, you'll get the y axis at the left edge of the plot. For making the axis a bit longer, you can set enlarge y limits=true. \documentclass[border=5mm]{standalone}

\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{arrows, positioning, calc}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
axis x line=middle,
axis y line=left,
enlarge y limits=true,
xmode=log, % Logarithmic x axis
xmin=0.01, xmax=1, % Positive domain...
xticklabel=\pgfmathparse{exp(\tick)}\pgfmathprintnumber{\pgfmathresult},
xticklabel style={/pgf/number format/.cd,fixed}, % Use fixed point notation
width=15cm, height=8cm,     % size of the image
grid = major,
grid style={dashed, gray!30},
ymin=-1,      % start the diagram at this y-coordinate
ymax= 1,      % end   the diagram at this y-coordinate
axis background/.style={fill=white},
ylabel=y,
xlabel=x,
legend style={at={(0.9,0.95)}, anchor=north}
]
\addplot[domain=0.01:1, red, thick,samples=2000] {-sin(deg(1/(x)))};
\legend{$\sin(\frac{1}{x})$}
\end{axis}
\end{tikzpicture}
\end{document}