LaTeX forum ⇒ Graphics, Figures & TablesPlot using tikz

Information and discussion about graphics, figures & tables in LaTeX documents.
pallav
Posts: 170
Joined: Wed Nov 12, 2008 5:53 pm

Plot using tikz

Postby pallav » Sun May 08, 2022 9:29 pm

\documentclass[tikz,border=13mm]{standalone}
\usetikzlibrary{arrows.meta,decorations.markings}
\usetikzlibrary{calc}
%\pgfplotsset{ticks=none}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}[>=stealth,declare function={f(\x)=\x^3/3-\x;}]
 \begin{axis}[name=MyAxis,grid=major,grid style=dotted , xmin=-2.2, xmax=2.2, ymin=-1.2, ymax=1.2,
          xlabel=$x\rightarrow$, ylabel={$y \rightarrow$}, 
				  xtick = {-2,-1,0,1,2},  xticklabels = {-2,-1,0,1,2},
					ytick = {-1,-.5,0,.5,1}, yticklabels={-1,-.5,0,.5,1},  %yticklabels=\empty,
         scale=1, restrict y to domain=0:.4,clip=false]
  \draw[scale=1,domain=-2.15:2.15,smooth,variable=\x,blue,thick] plot ({\x},{\x^3/3-\x});
  \draw[scale=1,red,fill=red] (1, -2/3) circle (.5ex);
  \draw[scale=1,red,fill=red] (-1, 2/3) circle (.5ex);
  \draw[scale=1,black] (0, 0) circle (.5ex);
    \draw[scale=1,red,thick,>={Stealth[round]},postaction=decorate,
  decoration={markings,
  	mark=at position 0.15 with {\arrow[black]{<.<}},
  	mark=at position 0.4 with {\arrow[black]{<}},
  	mark=at position 0.65 with {\arrow[black]{<.<}},
  	mark=at position 0.925 with {\arrow[black]{<}},
  }] % (-2,{f(-2)}) --(0,{f(.96)}) --  plot[variable=\x,domain=.96:.3479]  (\x,{f(\x)}) -- cycle; % Gamma_0 curve
(-2,{f(-2)}) -- (1,{f(1)})-- plot[variable=\x,domain=1:2] (\x,{f(\x)})--(-1,{f(-1)})--plot[variable=\x,domain=-1:-2] (\x,{f(\x)});
				\draw[scale=1,black,thick,rounded corners=8pt,postaction=decorate,
		decoration={markings,
			mark=at position 0.15 with {\arrow[black]{<.<}},
		mark=at position 0.4 with {\arrow[black]{<}},
		mark=at position 0.65 with {\arrow[black]{<.<}},
		mark=at position 0.925 with {\arrow[black]{<}},
		}] (-2,{f(-2)-0.05}) to[bend right=5] (1.05,{f(.95)}) --  plot[variable=\x,domain=1.05:2.05] (\x,{f(\x)+0.05}) --(-1-0.05,{f(-1)+0.05})--plot[variable=\x,domain=-1-0.05:-2+0.05] (\x,{f(\x)-0.05})--cycle;
				\end{axis}
\end{tikzpicture}
\end{document}



I want to get a plot like attached 1234.png file. I got sa.jpg. My code works perfect except at two corners of the black curve near the solid circles. Please correct my code.
Attachments
sa.jpg
sa.jpg (49.25 KiB) Viewed 331 times
1234.png
1234.png (18.75 KiB) Viewed 331 times

Recommended reading 2021:

LaTeXguide.org • LaTeX-Cookbook.net
LaTeX Beginner's Guide LaTeX Cookbook

Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: No registered users and 4 guests