嗨,我写了这段代码,但我不明白为什么它不是曲线。
\documentclass[12pt]{report}
\usepackage{tikz}
\begin{document}
\begin{figure} [htb]
\begin{tikzpicture}
\draw[-latex] (-2,0) -- (6,0) node[right] {$Return\%$};
\draw[-latex] (0,-4) -- (0,6) node[above] {$Utility$};
\draw (-2,-4) .. controls (0,0) and (0,0)..(5,5);
\end{tikzpicture}
\end{figure}
\end{document}
错误在哪里?
答案1
除了使用控制点(控制点指定曲线的方向,但不指定曲线本身的坐标,如 A. Ellet 的有用答案所示),您还可以绘制带平滑度的坐标图。添加更多坐标可使其更平滑。或者,pgfplots
您可以绘制一个看起来像您想要的曲线的数学函数,该函数在没有添加坐标或控制点的情况下会很平滑,但是找到正确的函数可能很困难。
梅威瑟:
\documentclass[12pt]{report}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\draw[step=1.0,lightgray,thin] (-2,-4) grid (7,4);
\draw[-latex] (-2,0) -- (7,0) node[right] {$Return\%$};
\draw[-latex] (0,-4) -- (0,4) node[above] {$Utility$};
\draw[blue] plot [smooth] coordinates { (-2,-4) (0,0) (3,2.5) (7,4) };
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[xmin=-2,xmax=6,ymin=-4,ymax=4,axis lines=middle,xlabel={return},ylabel={utility}]
\addplot[samples=200,domain=-2:6] {(-((x-5.5)*(x-5.5))+30)/8};
\end{axis}
\end{tikzpicture}
\end{document}
结果:
答案2
当然还有更强大的工具可用。不过,这里有一个简单的方法,可以实现:
代码如下:
\documentclass[12pt,border=6pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\def\aeAngleAB{80}
\def\aeAngleCD{55}
\def\aeANgleEF{5}
\begin{tikzpicture}[%%
%% control point/.style={inner sep=2pt,circle,draw=red},
control point/.style={inner sep=2pt,circle},
primary point/.style={inner sep=2pt,circle,draw=blue},
]
\draw[-latex] (-2,0) -- (6,0) node[right] {$Return\%$};
\draw[-latex] (0,-4) -- (0,6) node[above] {$Utility$};
\node[primary point] (P1) at (-2,-4) {};
\node[primary point] (P2) at (0,0) {};
\node[primary point] (P3) at (7,4) {};
\node[control point] (C1) at ($(P1)+(\aeAngleAB:10pt)$) {};
\node[control point] (C2) at ($(P2)+(180+\aeAngleCD:40pt)$) {};
\node[control point] (C3) at ($(P2)+(\aeAngleCD:110pt)$) {};
\node[control point] (C4) at ($(P3)+(180+\aeANgleEF:60pt)$) {};
%% \path[dashed,magenta,draw] (P1) -- (C1) -- (C2) -- (P2) -- (C3) -- (C4) -- (P3);
\path[dashed,magenta] (P1) -- (C1) -- (C2) -- (P2) -- (C3) -- (C4) -- (P3);
\draw[blue] (P1) .. controls (C1) and (C2) .. (P2);
\draw[blue] (P2) .. controls (C3) and (C4) .. (P3);
\end{tikzpicture}
\end{document}
添加draw=red
到键control point
并添加draw
到\path[dashed,magenta]
以查看控制点和图形之间的交互