# How to create this coordinate system?

I'm currently working on a term paper / lecture notes for my electrical engineering professor and wanted to include the following coordinate system / graph / figure in my paper. (The image should be rotated 90° to the left.)

My knowledge of TikZ / pstricks / pgfplots / ... is fairly restricted (to say the least) and therefore I'm really struggling in creating this thing. -.-

I tried my to get the coordinate system going, but the best I could come up with is:

\documentclass[tikz]{standalone}

\begin{document}
\begin{tikzpicture}
\tikzset{help lines/.style = {color = lightgray}}

\draw[thick, step=1cm, help lines] (-10, -10) grid (10, 10);
\draw[ultra thin, step=.5cm, help lines] (-10, -10) grid (10, 10);

\draw[ultra thick, -latex] (-10,0) -- (10,0);
\draw[ultra thick, -latex] (0,-10) -- (0,10);

\foreach \y in {-10,-9,...,10} { \draw [thick] (0, \y) -- (-0.2, \y); }

\foreach \y in {-10,-9,...,10} { \node [anchor = east] at (-0.3, \y) {\y}; }
\end{tikzpicture}
\end{document}

The y-axis in the image spans from -10 to 10. That's not a big issue, but the x-axis actually spans from 0 to 255, because it represents an 8bit intervall. That's the first thing I didn't knew how to do properly. And for the rest of the image I have no freaking clue how to do it all (especially the HEX/DEC caption above the coordinate system).

A "little" help and some of your guys magical powers would be much appreciated. :)

• Is the picture upside down? :D – Alenanno May 23 '15 at 12:08
• Yeah it actually should be rotated 90° left, but I couldn't figure out how to do it. ^^ – Chris.V May 23 '15 at 12:18

I changed your base code a bit because it was easier for setting the steps in the sheet. If you have any doubts, just ask me in the comments.

I wanted to set the top nodes using a \foreach and I was almost there, but unlike the numbering above, the top-top nodes have no logic in their succession, if you know what I mean, so I couldn't think of a rules to set them up the same way.

## Code

\documentclass[tikz,margin=10pt]{standalone}
\usepackage{amsmath}

\usetikzlibrary{calc,shapes}

\newcommand{\middlecoord}{13.6}
\newcommand{\middleline}{13.3}

\begin{document}
\begin{tikzpicture}
\tikzset{help lines/.style = {color = lightgray}}

\draw[thick, step=1cm, help lines] (0, -10) grid (27, 10);
\draw[ultra thin, step=2mm, help lines] (0, -10) grid (27, 10);

\draw[ultra thick, -latex] (0,0) -- (27,0) node[fill=white, above, pos=.9] {Digitalwerte}; % X
\draw[ultra thick, -latex] (\middleline,-10) -- (\middleline,10) node[fill=white, left, xshift=-1, pos=.95] {$U_A/V$}; % Y

\node[above=7mm,anchor=south] at (-1,10) {Hex.};
\node[above=3mm,anchor=south] at (-1,10) {Dez.};

\foreach \value/\acron [count=\xi starting from 0] in {
0/00H, 5/05H, 15/0FH, 25/19H, 35/23H, 45/2DH, 55/37H, 65/41H, 75/4BH, 85/55H, 95/63H, 105/69H, 115/72H, 125/79H,
135/87H, 145/91H, 155/9BH, 165/A5H, 175/AFH, 185/B9H, 195/C3H, 205/CDH, 215/D9H, 225/E1H, 235/EBH, 245/F5H, 255/FFH}{
\draw[lightgray, thick] (\xi+1, 10) -- (\xi+1,10.3);
\node[above=3mm,anchor=south] at (\xi,10) {\value};
\node[above=7mm,anchor=south] at (\xi,10) {\acron};
}

\node[above=3mm,anchor=south] at (\middlecoord,11) {128};
\node[above=7mm,anchor=south] at (\middlecoord,11) {7CH};
\draw[thick] (\middleline, 10) -- (\middleline,10.3) -- (\middlecoord,11.3);

\foreach \y in {-10,...,10}{
\node[fill=white,anchor=west] at (\middlecoord,\y) {\y};
\draw[thick] (\middleline-.2,\y) -- (\middleline+.2,\y);
}

\draw[thick, lightgray] (0,10.3) -- (.475,10); % diagonal line 0
\draw[lightgray] (.475,10) -- (.475,-10); % middle vertical line at 0
\draw[thick] (.475,-10) -- (26,10); % thick diagonal line

% ----------------------------------------
% The small rectangle in the bottom right
% ----------------------------------------

\node[draw,thick,minimum width=1.5cm,minimum height=1cm,ellipse] (ellc) at (\middlecoord-.25,0) {};
\filldraw[white] (15,-.5) -- (26.5,-.5) -- (26.5,-9.5) -- (15,-9.5) -- cycle;

\draw[ultra thick, -latex] (15.5,-5) -- (25,-5);
\draw[ultra thick, -latex] (20.5,-9) -- (20.5,-1) node[left, xshift=-1, pos=.95] {$U_A/mV$};

\draw[ultra thick] (21,-5) -- (21,-4) -- (22,-4) -- (22,-3) -- (23,-3) -- (23,-2) -- (24,-2); \draw[dashed, ultra thick] (24,-2) -- (24,-1);
\draw[ultra thick] (20,-5) -- (20,-6) -- (19,-6) -- (19,-7) -- (18,-7) -- (18,-8) -- (17,-8); \draw[dashed, ultra thick] (17,-8) -- (17,-9);

\foreach \x [count=\xxi starting from 123] in {16,17,...,24}{
\node[below=1mm,fill=white, font=\footnotesize] at (\x,-5) {\xxi};
\draw[ultra thick] (\x,-5) -- (\x,-5.1);
}

\draw ($(ellc.south east)+(.2cm,0)$) -- ($(ellc.south east)+(2.5cm,-1cm)$);

\draw[ultra thick] (20.4,-3) -- (20.5,-3); \node[left=1mm,font=\footnotesize] at (20.5,-3) {156.86};
\draw[ultra thick] (20.4,-4) -- (20.5,-4); \node[left=1mm,font=\footnotesize] at (20.5,-4) {78.43};
\draw[ultra thick] (20.5,-7) -- (20.6,-7); \node[right=1mm,font=\footnotesize] at (20.5,-7) {156.86};
\draw[ultra thick] (20.5,-8) -- (20.6,-8); \node[right=1mm,font=\footnotesize] at (20.5,-8) {235.29};
\end{tikzpicture}
\end{document}
• If you mean with the "top-top nodes" the hexadecimal numbers with suffix H, then they can be calculated (only the first number is an exception): \foreach \val [count=\xi starting from 0] in {-5, 5, ..., 255} {\ifnum\val<0 \def\val{0}\fi \draw[lightgray, thick] (\xi+1, 10) -- (\xi+1,10.3); \node[above=3mm,anchor=south] at (\xi,10) {\val}; \node[above=7mm,anchor=south] at (\xi,10) {\pgfmathsetbasenumberlength{2}\pgfmathdectoBase\mynumber{\val}{16}\mynumber H};} – Heiko Oberdiek May 23 '15 at 13:57
• @HeikoOberdiek Sorry I was not here. You're right, they're hexadecimal numbers! I'll look into it! Thanks! :D – Alenanno May 23 '15 at 17:29
• @HeikoOberdiek The result is slightly different. I'll list the differences: 5FH/95 instead of 63H/95, 73H/115 instead of 72H/115, 7DH/125 instead of 79H/125, D7H/215 instead of D9H/215. The rest is the same. Nice code though! :D – Alenanno May 23 '15 at 18:26
• Alenanno and @HeikoOberdiek: Damn, you guys really are some kind of magicians/wizards! That's exactly what I was looking for and the answer was so freaking fast. :) Thanks a lot. – Chris.V May 24 '15 at 18:02
• @Chris.V You're welcome and thank you, but Heiko is a bit more wizard-y. :D – Alenanno May 24 '15 at 18:05

Here's a pstricks solution. The graph box in the fourth quadrant is included as a zoomed.epsfile via \epsfbox (\includegraphics doesn't work, for some reason):

\documentclass[11pt, pdf, x11names]{standalone}
\usepackage{graphicx}
\usepackage{changes, stackengine}
\setstackEOL{\\}
\input{binhex}

\begin{document}

\psset{arrowinset=0, arrowsize =2.5pt 2, mathLabel=false, ylabelPos=r}
\sffamily
\begin{pspicture*}(-4,-10.2)(26,15)%[showgrid]
\psgrid[gridcolor=LightSteelBlue3,subgridcolor=LightSteelBlue2, gridlabels=0](-1,-10)(26.5,10)
\uput{10pt}[u](12.4,11.25){\Rnode{S}{\Longstack{\nhex{2}{128}H\\128}}}
\pnode(12.4,10){A}\ncline[nodesep=3pt]{S}{A}
\psset{linecolor=LightSteelBlue4!65!, origin={-0.5,0}}
\multido{\i =5+10, \n=0+1}{26}{\uput{10pt}[u](\n,10){\Longstack{\nhex{2}{\i}H\\\i}}}
\uput{10pt}[u](-1,10){\rnode{HD}{\Longstack{00H\\0}}}
\pnode(-0.5,10){O}\ncdiag[armA=6pt, angleB=90, nodesepB=2pt]{HD}{O}
\uput{10pt}[u](-2,10){\Longstack{Hex\\Dec}}
\psaxes[labels=y, labelsep=-10pt, ticks=none, linewidth=1.5pt]{->}(12.8,0)(-0.5,-10)(26.5,10) [\llap{Digitalwerte\qquad }, 100][\llap{U\textsubscript{A}/V\hskip2.5em}, -90]
\rput(12.75,0){ \ovalnode[linecolor=black]{F}{\phantom{Ahah!}}}
\rput[r]{*270}(-2.8,12){\itshape\rlap{Abbildung 3.4.1.2 Aufteilung desn, Wertebereichs (0 . . 255) des DA-Wandlers in Quantisierungsstufen}}
\uput{-10pt}[r](12.8,10){10}
\psline[linewidth=1.5pt](0,-10)(25.5,10)
\psline[doubleline](0,-10)(0,10)
\psnode(20,-5){MG}{%
\psframebox*[fillcolor=white, fillstyle=solid, framesep = 10pt] {%
\hskip-0.5cm\epsfbox{zoomed.eps}\hskip0.5cm }
}%
\ncline[linecolor=black]{F}{MG}
\end{pspicture*}

\end{document}

Code of zoomed.tex. Note the file had to be compiled with pdflatex and the resulting .pdf had to be converted to .eps, with epspdftk. I suppose the intermediate .eps file made by auto-pst-pdf might be saved, but I don't know how to do it.

%% zoomed.tex
\documentclass[pdf, x11names]{standalone}
\usepackage{changes}

\begin{document}

\psset{arrowinset=0, arrowsize =2.5pt 2, mathLabel=false, ylabelPos=r, linewidth=1.2pt, arrows=->, }
\sffamily\footnotesize
\begin{pspicture}%
\psaxes[tickstyle=b, Ox=128,yAxis=false](0,0)(-5.5,0)(4.,0)
\multido{\i=1+1, \n=78.43+78.43}{3}{\uput{8pt}[l](-0.5,\i){\n}\uput{8pt}[r](-0.5,-\i){$-$\n}}