1

The following display is that of a line and of a parabola on the Cartesian plane with grid lines. The grid lines are drawn nicely ... but to draw the grid lines I have included the axis options xtick={-7,-6,...,7}, and ytick={-5,-4,...,6},, and these options print all the numbers along the axes which makes a mess. Except for -3 and 3 along the x-axis and 4 along the y-axis, I would like all the labels for the tick marks removed. (Since I have a grid, I guess the tick marks themselves are redundant.)

I suppose that I don't need the tick marks or the labels -3, 3, and 4 for the tick marks printed. I could put the coordinates (-3,0), (3,0) and (0,4) in nodes and use the option fill=white. Any aesthetic suggestions would be appreciated.

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

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

\begin{document}
\begin{tikzpicture}

\begin{axis}[grid=both,grid style={line width=.1pt, draw=gray!10},major grid style={line width=.1pt,draw=gray!10}, clip=false,
    xmin=-7,xmax=7,
    ymin=-5,ymax=6,
    axis lines=middle,
    enlargelimits={abs=0.5},
    xtick={-7,-6,...,7},ytick={-5,-4,...,6},
    xticklabel style={fill=none},
    yticklabel style={fill=none},
    extra x ticks={-3,3},
    extra x tick labels={\,$-3$, $3$},
    extra x tick style={x tick label style={font=\tiny,fill=white}},
    extra y ticks={4},
    extra y tick labels={$4$},
    extra y tick style={y tick label style={above left, font=\tiny,fill=white}},
    axis line style={latex-latex},
    axis line style={shorten >=-7.5pt, shorten <=-7.5pt},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]

\addplot[latex-latex,samples=2,domain=-6.75:1.5] {(4/3) * x + 4} node[anchor=south east,pos=0.1,fill=white,font=\footnotesize]{$y = f(x)$};
\addplot[samples=201,domain=-4.5:4.5] {-(4/9) * x^2 + 4} node[anchor=south west,pos=0.6,fill=white,font=\footnotesize]{$y = g(x)$};

\end{axis}
\end{tikzpicture}

\end{document}
2

One way you could do it is to write:

xticklabels={,,,,-3,,}

and so on. Of course this is tedious and long to do. The method you were using was mostly correct: using only the extra tick labels to draw the ones you need, although you don't need \, in them.

If you want to make the regular labels empty, you have two ways of doing it, both valid (I used them both in my code):

xticklabels={\empty},
yticklabels={,,},

Also, you can apply the style to the tick labels. You can either set a style to the regular and extra tick labels independently, or you can use the regular yticklabel style={}, and it will apply to both.

Output

figure 1

Code

\documentclass{amsart}
\usepackage{tikz}
\usepackage{pgfplots}

\usetikzlibrary{calc}

\pgfplotsset{compat=1.11}

\begin{document}
\begin{tikzpicture}
\begin{axis}[grid=both,grid style={line width=.1pt, draw=gray!10},major grid style={line width=.1pt,draw=gray!10}, clip=false,
    xmin=-7,xmax=7,
    ymin=-5,ymax=6,
    axis lines=middle,
    enlargelimits={abs=0.5},
    xtick={-7,-6,...,7},
    ytick={-5,-4,...,6},
    xticklabels={\empty},
    yticklabels={,,},
    extra x ticks={-3,3},
    extra x tick labels={$-3$, $3$},
    extra y ticks={4},
    extra y tick labels={$4$},
    yticklabel style={anchor=south east},
    axis line style={latex-latex},
    axis line style={shorten >=-7.5pt, shorten <=-7.5pt},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]

\addplot[latex-latex,samples=2,domain=-6.75:1.5] {(4/3) * x + 4} node[anchor=south east,pos=0.1,fill=white,font=\footnotesize]{$y = f(x)$};
\addplot[samples=201,domain=-4.5:4.5] {-(4/9) * x^2 + 4} node[anchor=south west,pos=0.6,fill=white,font=\footnotesize]{$y = g(x)$};

\end{axis}
\end{tikzpicture}
\end{document}
  • I can do tedious. Since there are four commas before -3 and "nothing" typeset before them in xticklabels={,,,,-3,,,,,3,,,,,}, the four tick marks -7, -6, -5, and -4 are not typeset. How many commas would be needed between -3 and 3. If 0 is not considered a tick mark, five commas would be needed, and if 0 is considered a tick mark, four commas would be needed. – user74973 Jun 1 '15 at 12:58
  • @user74973 Whether you explicitly say 0 in that list or not, it'd be the same. I think it's irrelevant for the 0 tick mark. – Alenanno Jun 1 '15 at 13:08
  • Are you saying that the 0 tick mark is not printed? If that is the case, I could have xticklabels={,,,,-3,,,0,,,3,,,,,},. – user74973 Jun 1 '15 at 13:38
  • I would like to move the tick marks down a bit - maybe 2.5pt - so that they don't interfere with the parabola. I forgot the syntax to do this in an axis environment. – user74973 Jun 1 '15 at 13:39
  • 1
    @user74973 Indeed, it's not printed. Write xticklabel style={yshift=-2.5pt}, to shift them. – Alenanno Jun 1 '15 at 13:40
2

A PSTricks solution:

\documentclass{article}

\usepackage{pst-plot}
\psset{algebraic}

\begin{document}

\begin{figure}
 \centering
  \begin{pspicture}(-6,-3.5)(4.9,6.9) % boundry found manually
    % axes
    \psaxes[labels = none]{->}(0,0)(-5.5,-3.5)(4.5,6.5)[$x$,0][$y$,90]
    \uput[300](-3,0){$-3$}
    \uput[230](3,0){$3$}
    \uput[135](0,4){$4$}
    % labels
    \uput[150](-4.5,-2){$y = f(x)$}
    \uput[30](!2 20 9 div){$y = g(x)$}
    % graphs
    \psplot[linecolor = blue]{-5}{1.5}{4/3*x+4}
    \psplot[linecolor = red]{-4}{4}{-4/9*x^2+4}
  \end{pspicture}
 \caption{Add caption here.}
 \label{figure:something}
\end{figure}

\end{document}

output

1

This is not an elegant solution, but it may help you:

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

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

\begin{document}
\begin{tikzpicture}

\begin{axis}[grid=major,grid style={line width=.1pt, draw=gray!10},major grid style={line width=.1pt,draw=gray!10}, clip=false,
xmin=-7,xmax=5,
ymin=-5,ymax=6,
axis lines=middle,
enlargelimits={abs=0.5},
xtick=\empty,ytick=\empty,
extra x ticks={-7,-6,...,5},extra y ticks={-5,-4,...,6},
xticklabel style={fill=none},
yticklabel style={fill=none},
extra x tick labels={$\,$,$\,$,$\,$,$\,$,$\quad-3$,$\,$,$\,$,$\,$,$\,$,$\,$,$3\;$},
extra x tick style={x tick label style={font=\tiny}},
extra y tick labels={$\,$,$\,$,$\,$,$\,$,$\,$,$0$,$\,$,$\,$,$\,$,$4$},
extra y tick style={y tick label style={above left, font=\tiny}},
axis line style={latex-latex},
axis line style={shorten >=-7.5pt, shorten <=-7.5pt},
xlabel style={at={(ticklabel* cs:1)},anchor=north west},
ylabel style={at={(ticklabel* cs:1)},anchor=south west},axis equal
]

\addplot[latex-latex,samples=2,domain=-6.75:1.5] {(4/3) * x + 4} node[anchor=south east,pos=0.1,fill=white,font=\footnotesize]{$y = f(x)$};
\addplot[samples=201,domain=-4.5:4.5] {-(4/9) * x^2 + 4} node[anchor=south west,pos=0.6,fill=white,font=\footnotesize]{$y = g(x)$};
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

  • For the labels, why do you have $\,$? Why not $$ or {}? (I see that you had $\quad-3$, to move -3 further from one of the intersections of the graphs of $f$ and $g$. I think the minus sign does touch the line using just \,. Maybe using \,\, or \ would be fine.) – user74973 Jun 1 '15 at 12:10
  • Because that I wrote trick and no "solution", with $$ appears math mode, I didn't compiled that way. I prove with \, and \; but this is not sufficient translation for minus sign, you can try. – juanuni Jun 1 '15 at 23:31
  • I lowered the tick labels by 2pt. – user74973 Jun 1 '15 at 23:32
  • Is another way ... – juanuni Jun 1 '15 at 23:34
0

Here is another option for code that Alenanno suggested.

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

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

\begin{document}

\begin{tikzpicture}
\begin{tikzpicture}
\begin{axis}[grid=both,grid style={line width=.1pt, draw=gray!10},major grid style={line width=.1pt,draw=gray!10}, clip=false,
    xmin=-7,xmax=7,
    ymin=-5,ymax=6,
    axis lines=middle,
    enlargelimits={abs=0.5},
    xtick={-7,-6,...,7},ytick={-5,-4,...,6},
    xticklabels={,,,,$-3$,,,,,3,,,,,},yticklabels={,,,,,,,,,4,,},
    xticklabel style={yshift=-2pt, font=\tiny,fill=white},
    yticklabel style={above left, font=\tiny,fill=white},
    axis line style={latex-latex},
    axis line style={shorten >=-7.5pt, shorten <=-7.5pt},
    xlabel=$x$,ylabel=$y$,
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]

\addplot[latex-latex,samples=2,domain=-6.75:1.5] {(4/3) * x + 4} node[anchor=south east,pos=0.1,fill=white,font=\footnotesize]{$y = f(x)$};
\addplot[samples=201,domain=-4.5:4.5] {-(4/9) * x^2 + 4} node[anchor=south west,pos=0.6,fill=white,font=\footnotesize]{$y = g(x)$};
\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.