I am trying to plot a smooth, parabolic-like curve in LaTeX using TikZ or tkz-fct, and I need the curve to pass through the following specific points: (-2,0), (-1.5,-1), (-1,0),, (-0.5,0.5), (0,0), (0.5,-1), and (1,0) Horizontal arrows at (-1.5,-1) (-0.5,0.5) (0.5,-1) to looks like this one
I attempted to use a polynomial approximation, but the results were not smooth enough or parabolic in shape. The function I tried did not capture the correct curve through these points.
Here’s a simplified version of my attempts:
With pgfplots
\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis x line=middle,
axis y line=middle,
grid=both,
xmin=-3, xmax=3,
ymin=-2, ymax=2,
xtick={-2,-1,0,1,2},
ytick={-1,0,1},
width=10cm,
height=6cm,
domain=-2.5:2.5,
samples=200,
smooth,
thick,
every axis plot/.append style={thick},
enlargelimits
]
% Smooth curve with parabolic behavior passing through the points
\addplot[black,thick,smooth] coordinates {
(-2,0) (-1.5,-1) (-1,0) (-0.5,0.5) (0,0) (0.5,-1) (1,0)
};
% Horizontal arrows at the requested points
% Arrow at (-1.5, -1)
\draw[<->,thick] (axis cs:-1.8,-1) -- (axis cs:-1.2,-1);
% Arrow at (-0.5, 0.5)
\draw[<->,thick] (axis cs:-0.8,0.5) -- (axis cs:-0.2,0.5);
% Arrow at (0.5, -1)
\draw[<->,thick] (axis cs:0.2,-1) -- (axis cs:0.8,-1);
\end{axis}
\end{tikzpicture}
\end{document}
With tkz-fct
\documentclass{standalone}
\usepackage{tkz-fct}
\begin{document}
\begin{center}
\begin{tikzpicture}[gridded]
\tkzInit[xmin=-3,xmax=3,ymin=-2,ymax=2]
\tkzAxeX \tkzAxeY
\tkzGrid
% Plotting the approximated smooth curve passing through the points
\tkzFct[domain=-2:1,samples=1000,draw=black,thick]{0.84375*x**6 - 0.9375*x**5 - 3.28125*x**4 + 3.75*x**3 + 2.84375*x**2 - 1.375*x}
% Adding filled circles at specific points
\draw[fill=black] (-2,0) circle (2pt); % Point (-2, 0)
\draw[fill=black] (-1,0) circle (2pt); % Point (-1, 0)
\draw[fill=black] (0,0) circle (2pt); % Point (0, 0)
\draw[fill=black] (1,0) circle (2pt); % Point (1, 0)
% Adding open circle at (0.5, -1)
\draw[fill=white,draw=black] (0.5,-1) circle (2pt);
% Horizontal arrows at specific points
\draw[<->,thick] (-1.8,-1) -- (-1.2,-1); % Arrow at (-1.5, -1)
\draw[<->,thick] (-0.8,0.5) -- (-0.2,0.5); % Arrow at (-0.5, 0.5)
\draw[<->,thick] (0.2,-1) -- (0.8,-1); % Arrow at (0.5, -1)
\end{tikzpicture}
\end{center}
\end{document}
Unfortunately, this function doesn't fully capture the smooth parabolic-like shape I'm looking for. How can I create a parabolic-like curve that passes through the points above while keeping it smooth, preferably using tkz-fct or TikZ?
Any suggestions would be greatly appreciated!
hobby
package. That should allow you to make the necessary curves though any set of points.(x+2)*(x+1)*x*(x-1)
which happens to be close to the desired shape. All you need is to fit the last three points (divided by the given polynomial) to a quadratic. and multiply the two