12

Nothing exciting here. I have a plot with xmin=-11, xmax=11, ymin=-11, and ymax=11. I would like to use the grid option in the axis environment to draw a particular grid. All horizontal and vertical lines in the grid are to be drawn either between x=-10.5 and x=10.5 or between y=-10.5 and y=10.5 with line width=.1pt and draw=gray!10. The horizontal lines y=-10, y=-5, y=5, and y=10 and the vertical lines x=-10, x=-5, x=5, and x=10 are to be drawn with line width=.2pt and draw=gray!50. Tick marks at -10, -5, 5, and 10 are to be typeset on both axes and over these grid lines. I think the axis options xtick={-10,-5,5,10}, ytick={-10,-5,5,10}, and ticklabel style={font=\tiny,fill=white}, will put the tick marks over the grid.

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}


\begin{document}
\begin{tikzpicture}
\begin{axis}[grid style={line width=.1pt, draw=gray!10},major grid style={line width=.2pt,draw=gray!50},
    xmin=-11.75,xmax=11.75,
    ymin=-11.75,ymax=11.75,
    xtick={},ytick={},
    minor tick num=5,
    enlargelimits={abs=0},
    ticklabel style={font=\tiny,fill=white},
    axis lines=middle,
    axis line style={latex-latex},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]

\coordinate (O) at (0,0);
\node[fill=white,circle,inner sep=0pt] (O-label) at ($(O)+(-135:10pt)$) {$\scriptstyle{O}$};

\end{axis}
\end{tikzpicture}

\end{document}
18

Maybe I'm missing some obvious option, but I don't think you can reduce the grid to certain coordinates. There is nothing in the manual. You can fake this by lengthening the axes so that the grid looks more contained to fewer coordinates.

I set the number of grid lines to a certain value just as a demonstration. But you can increase/decrease their number by changing the value in this command (higher number = more lines):

minor tick num=5,

As I told you in the comments you can change the grid style locally. Just paste those options in the \begin{axis} options for the plot you want to change. I updated the example below to show this.

Output

figure 1

Code

\documentclass{amsart}
\usepackage[margin=2cm]{geometry}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    xmin=-11,xmax=11,
    ymin=-11,ymax=11,
    grid=both,
    grid style={line width=.1pt, draw=gray!10},
    major grid style={line width=.2pt,draw=gray!50},
    axis lines=middle,
    minor tick num=5,
    enlargelimits={abs=0.5},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]

\coordinate (O) at (0,0);
\node[fill=white,circle,inner sep=0pt] (O-label) at ($(O)+(-135:10pt)$) {$O$};

\end{axis}
\begin{axis}[xshift=9cm,
    xmin=-11,xmax=11,
    ymin=-11,ymax=11,
    grid=both,
    axis lines=middle,
    minor tick num=5,
    enlargelimits={abs=0.5},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]

\coordinate (O) at (0,0);
\node[fill=white,circle,inner sep=0pt] (O-label) at ($(O)+(-135:10pt)$) {$O$};

\end{axis}
\end{tikzpicture}
\end{document}

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.