2

I try to replicate the following graph

enter image description here

My very manual attempt is not pretty since curves are not properly connected.

Some of you speak path and controls much better than I do. A litte help on these would be much appreciated.

My question

How can I get the blue and green parts to be "in the continuity" of the red one ?

Edit

As a consequence of this "smooth continuity, I would love to see how to apply a gradient color on the connected lines [as in here] (Path following color gradient in TikZ)

enter image description here

enter image description here

My very manual 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}

JeT
  • 3,020

1 Answers1

4

The general problem using nodes like you do it, that they containg inner spacing, so it is often advisable to use coordinates which are just points. For the rest it is bascially just using the to sytnax with entrance and exit angles in and out. I also used intersections to ensure E and C are on the line from A to B, but that is just a detail and can be achieved manually as well.

\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}

enter image description here

EDIT: You can of course combine this approach with the colour gradient question you linked to. I take no credit, this is simply copy-paste and apply:

\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}

And just because I think it makes more sense to put the branches behind the main line, I added some layers.

enter image description here

Markus G.
  • 2,735
  • Thank you ! It works great. You were so fast I did not have time to amend and precise my question. I updated it regarding a color gradient at the connection points. If you don't mind, i'll wait a bit to validate your answer :) – JeT Sep 28 '21 at 13:12
  • As per your request I added a possible combination of my answer with the one you linked to. It is for sure not perfect, but if you want a smoother gradient it is going to be a lot more complicated for sure. – Markus G. Sep 28 '21 at 13:29
  • Perfect, Looks great. – JeT Sep 28 '21 at 13:31