我尝试复制以下图表
由于曲线没有正确连接,我的手动尝试并不理想。
你们中有些人的口语path
比controls
我好得多。如果能提供一点帮助,我将不胜感激。
我的问题
我怎样才能使蓝色和绿色部分与红色部分“连续”?
编辑
由于这种“平滑的连续性”,我很想看看如何在连接的线上应用渐变颜色(如这里所示)(TikZ 中的路径跟随颜色渐变)
我的非常手动的MWE
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw[step=1.0,gray,thin] (0,0) grid (10,10);
\node at (2,10) (nodeA) {A};
\node at (10,2) (nodeB) {B};
\node at (4.7,3.2) (nodeC) {C};
\node at (10,3.2) (nodeD) {D};
\node at (3,5.2) (nodeE) {E};
\node at (0.5,6.5) (nodeF) {F};
\draw[red,ultra thick, bend right=45, looseness=1.2] (nodeA) to (nodeB);
\draw[green,ultra thick, bend right=1] (nodeC) to (nodeD);
\draw[blue,ultra thick, bend right=30, looseness=1.2] (nodeE) to (nodeF);
\draw [<->,thick] (0,10) node (yaxis) [left,rotate=90] {Bond price}
|- (10,0) node (xaxis) [below] {Bond yield};
\end{tikzpicture}
\end{document}
答案1
使用 s 的一般问题node
是它们包含内部间距,因此通常建议使用coordinate
s,即点。其余部分基本上只是使用to
具有入口和出口角的 sytnaxin
和out
。我还曾经intersections
确保 E 和 C 在从 A 到 B 的线上,但这只是一个细节,也可以手动实现。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}
\begin{document}
\begin{tikzpicture}[>=stealth,every node/.style={text=black}]
\draw[step=1.0,gray,thin] (0,0) grid (10,10);
\coordinate (D) at (10,2.8);
\coordinate (F) at (0.5,6.5);
\draw[red,ultra thick,looseness=1.2,name path=redline] (2,10) node[anchor=south] (A) {A} to[out=270,in=180] (10,2) node[anchor=west] (B){B};
\path[name path=helpE] (0,5.2) -- ++(10,0);
\path[name path=helpC] (0,4) -- ++(10,0);
\path [name intersections={of=redline and helpE,by=E}];
\path [name intersections={of=redline and helpC,by=C}];
\draw[green,ultra thick] (C) node[anchor=south]{C} to[out=325,in=180] (D) node[anchor=west]{D};
\draw[blue,ultra thick] (F) node[anchor=south]{F} to[out=0,in=120] (E) node[anchor=west] {E};
\draw [<->,thick] (0,10) node (yaxis) [anchor=south east,rotate=90] {Bond price}
|- (10,0) node (xaxis) [anchor=north east] {Bond yield};
\end{tikzpicture}
\end{document}
编辑:当然,你可以将这种方法与你链接的颜色渐变问题结合起来。我不承担任何责任,这只是复制粘贴并应用:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,intersections,decorations.markings}
\pgfdeclarelayer{background}
\pgfsetlayers{background, main}
\tikzset{test/.style n args={3}{
postaction={
decorate,
decoration={
markings,
mark=between positions 0 and \pgfdecoratedpathlength step 0.4pt with {
\pgfmathsetmacro\myval{multiply(
divide(
\pgfkeysvalueof{/pgf/decoration/mark info/distance from start}, \pgfdecoratedpathlength
),
100
)};
\pgfsetfillcolor{#3!\myval!#2};
\pgfpathcircle{\pgfpointorigin}{#1};
\pgfusepath{fill};}
}}}}
\begin{document}
\begin{tikzpicture}[>=stealth,every node/.style={text=black}]
\draw[step=1.0,gray,thin] (0,0) grid (10,10);
\coordinate (D) at (10,2.8);
\coordinate (F) at (0.5,6.5);
\draw[red,ultra thick,looseness=1.2,name path=redline] (2,10) node[anchor=south] (A) {A} to[out=270,in=180] (10,2) node[anchor=west] (B){B};
\begin{pgfonlayer}{background}
\path[name path=helpE] (0,5.2) -- ++(10,0);
\path[name path=helpC] (0,4) -- ++(10,0);
\path [name intersections={of=redline and helpE,by=E}];
\path [name intersections={of=redline and helpC,by=C}];
\draw[test={0.8pt}{red}{green},ultra thick] (C) node[anchor=south]{C} to[out=325,in=180] (D) node[anchor=west]{D};
\draw[test={0.8pt}{blue}{red},,ultra thick] (F) node[anchor=south]{F} to[out=0,in=120] (E) node[anchor=west] {E};
\end{pgfonlayer}
\draw [<->,thick] (0,10) node (yaxis) [anchor=south east,rotate=90] {Bond price}
|- (10,0) node (xaxis) [anchor=north east] {Bond yield};
\end{tikzpicture}
\end{document}
而且因为我认为把分支放在主线后面更有意义,所以我添加了一些层。