我想找到曲线的最大值并显示如下图所示的值。我在这个论坛中找不到适用于我的情况的任何示例。
\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{units}
\begin{document}
\begin{tikzpicture}
\begin{axis}[change y base,
x unit= ,
% y SI prefix=kilo,
y unit= ,
xmin=0, xmax=1,
ymin=0, ymax=1.1,
% ytick={0,1000,...,6000},
xlabel=Degree,
ylabel=Force,
xlabel={$S_r$},
ylabel={$F_x/F_z$},
xlabel style={below right},
ylabel style={above left},
height=8cm,
width=9cm,
grid=minor,
samples=99,
trig format plots=rad
]
\newcommand\SV{80.1}
\newcommand\SH{0}
\newcommand\B{0.210}
\newcommand\C{1.67}
\newcommand\D{6090}
\newcommand\E{0.686}
\newcommand\Fz{6000}
\addplot[domain=0:1, blue, thick] {(\SV+\D*sin(\C*atan(\B*(1-\E)*(x*100+\SH)
+( atan(\B*(x*100+\SH))
)
)
)
)/\Fz
};
\addlegendentry{$F_x(F_z=6kN)$}
\end{axis}
\end{tikzpicture}
\end{document}
答案1
在这个帖子我现在已经能够绘制我想要的内容(无需进行导数计算)。
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{units}
\makeatletter
\pgfplotsset{
/tikz/max node/.style={
anchor=south,
},
/tikz/min node/.style={
anchor=north,
name=minimum
},
mark min/.style={
point meta rel=per plot,
visualization depends on={x \as \xvalue},
scatter/@pre marker code/.code={%
\ifx\pgfplotspointmeta\pgfplots@metamin
\def\markopts{}%
\coordinate (minimum);
\node [min node] {
\pgfmathprintnumber[fixed]{\xvalue},%
\pgfmathprintnumber[fixed]{\pgfplotspointmeta}
};
\else
\def\markopts{mark=none}
\fi
\expandafter\scope\expandafter[\markopts,every node near coord/.style=green]
},%
scatter/@post marker code/.code={%
\endscope
},
scatter,
},
mark max/.style={
point meta rel=per plot,
visualization depends on={x \as \xvalue},
scatter/@pre marker code/.code={%
\ifx\pgfplotspointmeta\pgfplots@metamax
\def\markopts{}%
\coordinate (maximum);
\node [max node] {
\pgfmathprintnumber[fixed]{\xvalue},%
\pgfmathprintnumber[fixed]{\pgfplotspointmeta}
};
\else
\def\markopts{mark=none}
\fi
\expandafter\scope\expandafter[\markopts]
},%
scatter/@post marker code/.code={%
\endscope
},
scatter
}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\begin{axis}[change y base,
x unit= ,
% y SI prefix=kilo,
y unit= ,
xmin=0, xmax=1,
ymin=0, ymax=1.1,
% ytick={0,1000,...,6000},
xlabel=Degree,
ylabel=Force,
xlabel={$S_r$},
ylabel={$F_x/F_z$},
xlabel style={below right},
ylabel style={above left},
height=8cm,
width=9cm,
grid=minor,
samples=199,
trig format plots=rad,
domain=0:1, blue,
axis lines*=middle,after end axis/.code={
\draw [thick, dashed, gray] (maximum) --({axis cs:0,0}-|maximum);}
]
\newcommand\SV{80.1}
\newcommand\SH{0}
\newcommand\B{0.210}
\newcommand\C{1.67}
\newcommand\D{6090}
\newcommand\E{0.686}
\newcommand\Fz{6000}
\addplot +[mark max] plot {(\SV+\D*sin(\C*atan(\B*(1-\E)*(x*100+\SH)
+( atan(\B*(x*100+\SH))
)
)
)
)/\Fz
};
\addlegendentry{$F_x(F_z=6kN)$}
\end{axis}
\end{tikzpicture}
\end{document}