$\pm (2/3)\sqrt{3}$
我在轴上有刻度标记x
。如何防止对这些刻度标记的标签进行排版?
\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}
答案1
正如我在在问题下方评论添加时xticklabels={}
仍然显示给定的刻度,但不显示任何标签。
(除此之外,我对您的代码做了一些修改/改进,以便现在可以更轻松地根据引脚位置更改蓝点、相应的切线和垂直引脚。有关更多详细信息,请查看代码中的注释。)
% 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}
答案2
您可以使用xticklabel=\relax
或xticklabels={}
来防止 pgfplots 在 x 轴上为刻度添加标签。