2

As you can see from the screenshot of the output, the grid lines extend through the tick labels. How would you keep the grey grid lines within the first quadrant?

Many thanks

output

\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\renewcommand{\thesection}{\arabic{section}}
\usepackage{mathtools}
\usepackage{cancel}
\usepackage{pgfplots}
\usepackage{amsmath}
\newtheorem{theorem}{THEOREM}
\newtheorem{proof}{PROOF}
\usepackage{tikz}
\usepackage{amssymb}
\usetikzlibrary{patterns}
\usetikzlibrary{arrows}
\usetikzlibrary{shapes.misc}
\usepackage{flexisym}
\usetikzlibrary{arrows}
\newenvironment{tightcenter}{
\setlength\topsep{0pt}
\setlength\parskip{0pt}
\begin{center}}{\end{center}}
\begin{document}
\tikzset{options/.code={\tikzset{#1}}} % just to compact the code
\thispagestyle{empty}
\setcounter{page}{1}
\textbf{Question 1} (5 marks)\\[0.124cm]
\begin{center}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
grid=major,
xmin=-1,
xmax=11,
ymin=-1,
ymax=13,
xlabel=$x$,
ylabel=$y$,
xtick={0,1,...,10},
ytick={0,1,...,12},
scale=1.9,
transform shape,
tick style={very thick},
legend style={
at={(rel axis cs:0,1)},
anchor=north west,draw=none,inner sep=0pt,fill=gray!10}
]
%
%line of best fit
\plot[thick,samples=150,domain=0:10] {1.2*x-0.8};
\end{axis}
\newline
\end{tikzpicture}
\end{center}
\end{document}
  • 2
    How about just setting xmin=0,ymin=0? – user121799 Jun 10 '18 at 6:24
  • Oh wow, that worked perfectly! How do I put your suggestion as a solution? :) – Will Kim Jun 10 '18 at 6:27
  • I just wrote a quick answer. To make it more worthwhile, I also commented on the general solution. – user121799 Jun 10 '18 at 14:45
2
\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\tikzset{options/.code={\tikzset{#1}}} % just to compact the code
\thispagestyle{empty}
\setcounter{page}{1}
\textbf{Question 1} How to remove the grid left of the $y$- and below the
$x$--axis\\[0.124cm]
\begin{center}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
grid=major,
xmin=0,
xmax=11,
ymin=0,
ymax=13,
xlabel=$x$,
ylabel=$y$,
xtick={0,1,...,10},
ytick={0,1,...,12},
scale=1.9,
transform shape,
tick style={very thick},
legend style={
at={(rel axis cs:0,1)},
anchor=north west,draw=none,inner sep=0pt,fill=gray!10}
]
%
%line of best fit
\plot[thick,samples=150,domain=0:10] {1.2*x-0.8};
\end{axis}
\end{tikzpicture}
\end{center}


\textbf{Question 2} How to prevent the grid from running through the ticks\\[0.124cm]
\begin{center}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
grid=major,
xmin=-3,
xmax=6,
ymin=-3,
ymax=6,
xlabel=$x$,
ylabel=$y$,
xtick={-2,-1,...,5},
ytick={-2,-1,...,7},
scale=1.9,
transform shape,
ticklabel style={
            fill=white
        },
tick style={very thick},
legend style={
at={(rel axis cs:0,1)},
anchor=north west,draw=none,inner sep=0pt,fill=gray!10}
]
%
%line of best fit
\plot[thick,samples=150,domain=-3:6] {1.2*x-0.8};
\end{axis}
\newline
\end{tikzpicture}
\end{center}

\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.