Quantcast
Viewing all articles
Browse latest Browse all 3

Labeling node values on the axes

I want to draw some curves and some special coordinates on the curves, then label the nodes on the axes. So far I have done it manually like this (it's a diagram for the Markowitz risk premium in case you have heard of it):

\documentclass{article}\usepackage[utf8]{inputenc}\usepackage{tikz}\usepackage{pgfplots}\usetikzlibrary{calc,intersections,through,backgrounds}\title{Plotty}\date{October 2013}\begin{document}\begin{tikzpicture}[scale=1]    \begin{axis}[xmin=0,ymin=0,ymax=10,xmax=10,xticklabels={,,},yticklabels={,,},axis x line=center,axis y line=center,clip=false,                    xlabel=$w$,ylabel=$U(x)$]        \draw[name path=ucurve] (axis cs:0,0) .. controls (axis cs:2,9) .. (axis cs:10,10) coordinate[pos=0.2](n1) coordinate[pos=0.9](n2);        \draw[name path=eucurve] (n1) -- (n2) coordinate[pos=0.5](n3);        \draw[dotted] let \p1 = (n3) in (n3) -- (\x1,0) node[below,blue]{$E(w)$};        \draw[dotted,name path global=uintersect] let \p1 = (n3) in (n3) -- (0,\y1) node[left,blue]{$E(U(w))=U(E(w)-\pi)$};        %Calculate the intersection        \draw[dotted,name intersections={of=ucurve and uintersect,by=I}] let \p1 = (I) in (I) -- (\x1,0) node[below,blue]{$E(w)-\pi$};        \draw[dotted] let \p1 = (n1) in (n1) -- (\x1,0) node[below,blue]{$90$};        \draw[dotted] let \p1 = (n1) in (n1) -- (0,\y1) node[left,blue]{$U(90)$};        \draw[dotted] let \p1 = (n2) in (n2) -- (\x1,0) node[below,blue]{$P_u$};        \draw[dotted] let \p1 = (n2) in (n2) -- (0,\y1) node[left,blue]{$U(P_u)$};    \end{axis}\end{tikzpicture}\end{document}

Image may be NSFW.
Clik here to view.
enter image description here

As you can see, I'm trying to do this manually by generating the paths to the axes. However, things get quite messy because I don't take into account the label size.

  1. How can I avoid the overlapping labels? I feel that there must be a plot option or something to label coordinates on the axes.

  2. How can I optimize my code? I'm just starting with pgfplots and I've found out there are hundreds of ways to achieve the same results, so maybe I'm not doing this right. Particularly the intersections library seems overkill for my needs...


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>