4

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

  • You are simply confusing ylabel style and yticklabel style, I think. – user121799 Aug 15 '18 at 16:13
7

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

  • Thank you, super knowledgeable and helpful as always. Your code is very simple and tidy! – Will Kim Aug 15 '18 at 16:21
3

Based on @marmot's answer and just for fun (though it is quite ugly) a small animation to see the effect of the rotate option

\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}}
\usepackage{animate}

\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{animateinline}[controls,loop]{3}
  \multiframe{72}{ixb=0+15}{
\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,
rotate=\ixb
},
ylabel=Y LABEL,
xticklabel style={
%xshift=10pt,
fill=white,
rotate=\ixb
},
xlabel=X,
ylabel near ticks,
xlabel near ticks,
ylabel style={rotate=0},
]
\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{animateinline}
\end{center}
\end{document}
0

slightly modified nice marmot's answer (differences are indicated in code by % <---):

\documentclass[margin=3mm]{standalone}
%removed all not related definitions and packages
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}               % <---

\begin{document}
    \begin{tikzpicture}
\begin{axis}[
height=11cm, width=13cm,
restrict y to domain=0:70,              % <---
domain=0:70,                            % <---
samples=141,                            % <---
no marks,                               % <---
clip=false,                             % <---
% some fine-tuning for the display:
xmin=0, xmax=70,
ymin=0, ymax=70,
xtick={0,5,...,70},                     % <---
ytick={0,5,...,70},                     % <---
grid,
axis lines=center,                      % <---
axis line style={shorten >=-10pt, shorten <=-10pt},
ylabel=Y LABEL,
xlabel=X,
ylabel near ticks,
xlabel near ticks,
ylabel style={rotate=-90},
]
\addplot +[ultra thick] {3*x+3.739};    % <---
\node[below left] at (0,0) {$O$};       % <---
\fill   (50,45) circle (3pt);           % <---
\end{axis}
    \end{tikzpicture}
\end{document}

enter image description here

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.