如何在 tikz 中绘制曲线

如何在 tikz 中绘制曲线

很抱歉提出这个初学者问题,我正在尝试画这幅图在此处输入图片描述

我对此遇到了困难。

我试过

\pgfplotsset{
    standard/.style={
    axis line style = thick,
    trig format=deg,
    enlargelimits,
    axis x line=middle,
    axis y line=middle,
    enlarge x limits=0.15,
    enlarge y limits=0.15,
    every axis x label/.style={at={(current axis.right of origin)},anchor=north west},
    every axis y label/.style={at={(current axis.above origin) },anchor=south east},
    grid=both,
    ticklabel style={font=\tiny, fill=white}
 }
}
  
\begin{tikzpicture}
  \begin{axis}[standard,
      xtick={-2,-1,...,4},
      ytick={-1,0,...,3},
      xticklabel={\pgfmathprintnumber{\tick}},
      yticklabel={\pgfmathprintnumber{\tick}},
      xlabel={ $x$},
      ylabel={ $y$},
      samples=1000,
      xmin=-2, xmax=4.3,
      ymin=-1, ymax=3.3,
      title={title here},
      title style={at={({0.5,1.1})},anchor=north}]

      \node[anchor=center, label=south west:$O$] at (axis cs:0,0){};
      \draw[red, thick] (axis cs: -2,0) -- (axis cs: -1,3) .. controls (axis cs: -0.5,2) and (axis cs: 0,2) .. (axis cs: 1,1);
  \end{axis}
\end{tikzpicture}

      \draw[red, thick] (axis cs: -2,0) to [out=35,in=-160] (axis cs: -1,3) coordinate (A);

没有更好

答案1

\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\pgfplotsset{
standard/.style={
axis line style=thick,
trig format=deg,
enlargelimits,
axis x line=middle,
axis y line=middle,
enlarge x limits=0.15,
enlarge y limits=0.15,
every axis x label/.style={at={(current axis.right of origin)},anchor=north west},
every axis y label/.style={at={(current axis.above origin) },anchor=south east},
grid=both,
ticklabel style={font=\tiny, fill=white}
}}
\begin{document}
\begin{tikzpicture}
\begin{axis}[standard,
xmin=-2, xmax=4.3,
ymin=-1, ymax=3.3,
xtick distance=1, ytick distance=1,
xlabel={$x$}, ylabel={$y$},
title={title here},
title style={at={({0.5,1.1})},anchor=north}
]
\node[below left] at (0,0) {$O$};
\draw[red, thick, looseness=0.3] (-2,0) to[out=60, in=180] (-1,3) to[out=0, in=180] (1,-1) to[out=0, in=-120] (2,3) -- (4,1);
\end{axis}
\end{tikzpicture}
\end{document}

带有红色曲线的图表

相关内容