[Tex/LaTex] Graph axis label rotation

tikz-pgf

I thought

ylabel style={rotate=-90}

would prevent my y-axis rotation but it is still happening for some reason.
It seems that the grid lines are still going through the tick labels even after I put

fill=white

Below is my code:

\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\renewcommand{\thesection}{\arabic{section}}
\usepackage{pgfplots}
\usepackage{amsmath}
\newtheorem{theorem}{THEOREM}
\newtheorem{proof}{PROOF}
\usetikzlibrary{shapes.misc}
\usetikzlibrary{arrows}
\usepgfplotslibrary{statistics}
\usetikzlibrary{shapes.multipart,shapes.geometric,calc,angles,positioning,intersections,quotes,decorations,babel,patterns,fit}
\usetikzlibrary{decorations.markings}
\newenvironment{tightcenter}{
\setlength\topsep{0pt}
\setlength\parskip{0pt}
\begin{center}}{\end{center}}
\begin{document}
% !TeX spellcheck = en_GB 
\tikzset{%
insert new path/.style={%
insert path={%
node[midway,sloped]{\tikz \draw[#1,thick] (-.2pt,0) -- ++(.2 pt,0);}
}
}
}
\thispagestyle{empty}
\setcounter{page}{1}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
grid=major,
%ticks=none,
xmin=-3,
xmax=70,
ymin=-3,
ymax=70,
xtick={0,5,10,15,20,25,30,35,40,45,50,55,60,65,70},
ytick={0,5,10,15,20,25,30,35,40,45,50,55,60,65,70},
height=11cm,
width=13cm,
axis line style={shorten >=-10pt, shorten <=-10pt},
ylabel style={
fill=white,
yshift=10pt,
rotate=-90
},
ylabel=Y LABEL,
xlabel style={
xshift=10pt,
fill=white
},
xlabel=X,
ylabel near ticks,
xlabel near ticks,
]
\node[below] at (axis cs:-1.5,0) {$O$};
\draw[fill=black](axis cs:50,45) circle (3pt);
\addplot[thick,color=black,samples=100,domain=0:70] {3*x+3.739};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}

and the output is

output

Can anyone please suggest where have I gone wrong?

Thanks

Best Answer

I think you need to distinguish between ylabel style and yticklabel style. I also moved ylabel style={rotate=-90}, down to make it work. It has to be below ylabel near ticks, since otherwise the rotation gets overwritten (or is not yet defined).

\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\renewcommand{\thesection}{\arabic{section}}
\usepackage{pgfplots}
\usepackage{amsmath}
\newtheorem{theorem}{THEOREM}
\newtheorem{proof}{PROOF}
\usetikzlibrary{shapes.misc}
\usetikzlibrary{arrows}
\usepgfplotslibrary{statistics}
\usetikzlibrary{shapes.multipart,shapes.geometric,calc,angles,positioning,intersections,quotes,decorations,babel,patterns,fit}
\usetikzlibrary{decorations.markings}
\newenvironment{tightcenter}{
\setlength\topsep{0pt}
\setlength\parskip{0pt}
\begin{center}}{\end{center}}
\begin{document}
% !TeX spellcheck = en_GB 
\tikzset{%
insert new path/.style={%
insert path={%
node[midway,sloped]{\tikz \draw[#1,thick] (-.2pt,0) -- ++(.2 pt,0);}
}
}
}
\thispagestyle{empty}
\setcounter{page}{1}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
grid=major,
%ticks=none,
xmin=-3,
xmax=70,
ymin=-3,
ymax=70,
xtick={0,5,10,15,20,25,30,35,40,45,50,55,60,65,70},
ytick={0,5,10,15,20,25,30,35,40,45,50,55,60,65,70},
height=11cm,
width=13cm,
axis line style={shorten >=-10pt, shorten <=-10pt},
yticklabel style={
fill=white,
%yshift=10pt,
},
ylabel=Y LABEL,
xticklabel style={
%xshift=10pt,
fill=white
},
xlabel=X,
ylabel near ticks,
xlabel near ticks,
ylabel style={rotate=-90},
]
\node[below] at (axis cs:-1.5,0) {$O$};
\draw[fill=black](axis cs:50,45) circle (3pt);
\addplot[thick,color=black,samples=100,domain=0:70] {3*x+3.739};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}

enter image description here