0

I have tick marks at $\pm (2/3)\sqrt{3}$ on the x-axis. How do I prevent the typesetting of the labels for these tick marks?

\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}

\usepackage{tikz}
\usetikzlibrary{calc,intersections}

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

\begin{document}


\begin{tikzpicture}
\begin{axis}[width=3.5in, height=3.5in, axis lines=middle, clip=false,
    axis lines=middle, clip=false,
    xmin=-2.5251,xmax=2.4567,
    ymin=-3,ymax=8,
    restrict y to domain=-3:8,
    xtick={-1.1547, 1.1547}, ytick={\empty},
    axis line style={latex-latex},
    xlabel=$x$,ylabel=$y$,
    axis line style={shorten >=-12.5pt, shorten <=-12.5pt},
    xlabel style={at={(ticklabel* cs:1)}, xshift=12.5pt, anchor=north west},
    ylabel style={at={(ticklabel* cs:1)}, yshift=12.5pt, anchor=south west}
]


\addplot[samples=501, domain=-2.5251:2.4567] {x^3 - 4*x + 3};
\addplot[samples=2, latex-latex, dashed, domain=-2.5251:2.4567] {-x + 5};

\fill[blue] (-1, 6) circle [radius=1.5pt];

%P = (2.25, 5.390625) is a point on the graph of y = x^{3} - 4x + 3.
%The slope of the tangent line at P is 11.1875. An equation for the
%tangent line is y = 11.1875x -19.78125. Q = (1.786816, 0) is the
%x-intercept for the line.
\coordinate (P) at (2.25, 5.390625);
\coordinate (Q) at (1.786816, 0);

\end{axis}


%A "pin" is drawn to the cubic polynomial.
\draw[draw=gray, shorten <=1mm, shorten >=1mm] (P) -- ($(P)!0.75cm!90:(Q)$);
\node[anchor=west, inner sep=0, font=\footnotesize] at ($(P)!0.75cm!90:(Q)$){\makebox[0pt][l]{$y = x^{3} - 4x + 3$}};

\end{tikzpicture}

\end{document}
cgnieder
  • 66,645

2 Answers2

2

As I already stated in the comment below the question adding xticklabels={} still shows the given ticks but does not show any labels on them.

(Besides that I made some modifications/improvements to your code so that it is much easier now to change the blue point, the corresponding tangent line and the perpendicular pin depending on the pin position. For more details please have a look at the comments in the code.)

% used PGFPlots v1.14
\documentclass[border=15pt]{standalone}
\usepackage{pgfplots}
    \usetikzlibrary{calc}
    \pgfplotsset{
        compat=1.11,
        % declare the functions you want to plot
        /pgf/declare function={
            % the function to plot
            f(\x) = (\x)^3 - 4*(\x) + 3;
            % first derivative of the function
            % (giving the slope at a given point `\x')
            g(\x) = 3*(\x)^2 - 4;
            % "point-slope form of a line" going through x=0
            % (I don't know the English translation for the German
            %  "Punktsteigungsform einer Geraden")
            h(\x) = g(\x) * (-\x) + f(\x);
        },
    }
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        width=3.5in,
        height=3.5in,
        axis lines=middle,
        axis line style={
            latex-latex,
            shorten >=-12.5pt,
            shorten <=-12.5pt,
        },
        xmin=-2.5251,
        xmax=2.4567,
        ymin=-3,
        ymax=8,
        xtick={-1.1547, 1.1547},
        % ---------------------------------------------------------------------
        % this does not show any labels at the ticks
        xticklabels={},
        % ---------------------------------------------------------------------
        ytick={\empty},
        xlabel=$x$,
        ylabel=$y$,
        xlabel style={at={(ticklabel* cs:1)}, xshift=12.5pt, anchor=north west},
        ylabel style={at={(ticklabel* cs:1)}, yshift=12.5pt, anchor=south west},
        % moved common `\addplot' key here
        domain=-2.5251:2.4567,
    ]

        % here you now just call the above defined function
        % (I also reduced the number of `samples' and added the option
        %  `smooth' which gives almost the same result)
        \addplot [samples=51, smooth] {f(x)};
            % define a constant at which x value you want to plot the tangent line
            \pgfmathsetmacro{\X}{-1}
        % now you can easily draw the tangent line with the use of the above
        % defined other functions ...
        \addplot [samples=2, latex-latex, dashed] {g(\X)*x + (h(\X))};

        % ... as well as drawing the circle
        \fill [blue] ({\X}, {f(\X)}) circle [radius=1.5pt];

        % give a value to `\XX' to calculate the point P on `f(x)'
        % then calculate point Q which is the point on x=0 of the tangent line
        % going through point P
            \pgfmathsetmacro{\XX}{2.25}
        \coordinate (P) at (\XX, {f(\XX)});
        \coordinate (Q) at ( 0, {h(\XX)});

    \end{axis}

    % A "pin" is drawn to the cubic polynomial.
    \draw [draw=gray, shorten <=1mm, shorten >=1mm]
        (P) -- ($(P)!0.75cm!90:(Q)$);
    \node [anchor=west, inner sep=0, font=\footnotesize]
        at ($(P)!0.75cm!90:(Q)$){$y = x^{3} - 4x + 3$};

\end{tikzpicture}
\end{document}

image showing the result of above code

Stefan Pinnow
  • 29,535
0

You can use either xticklabel=\relax or xticklabels={} to prevent pgfplots from adding labels to your ticks on the x axis.