Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How to achieve this kind of axis with pgfplot ? Image taken from Szymon Beczkowski's awesome PhD thesis design (thesis link)

Credit to Beczkowski, Szymon

I may provide you with some data to play with.

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[xlabel={$L$ [H]},ylabel={$\hat{I}_{DM}$ [A]},axis lines*=left,grid,xtick=data]
  \addplot coordinates {(948e-6,1.61981) (1.5e-3,1.02377) (2e-3,0.769047) (2.5e-3,0.614994) (3e-3,0.503511)};
\end{axis}
\end{tikzpicture}
\end{document}
share|improve this question
2  
This thesis is truly amazing. Is there a TeX source for it? –  biologue Jan 21 at 17:50
    
Ask the author. I'd be very interested as well. –  s__C Jan 21 at 18:05
8  
Here is the main source file pastebin.com/7dPDyucr and also the whole project so you can build it yourself (tables, graphics and bibliography) dl.dropboxusercontent.com/u/487668/Thesis.zip Hope it will be useful for you. –  Szymon Bęczkowski Jan 22 at 10:13
    
@SzymonBęczkowski Thank you very much. –  s__C Jan 22 at 11:32

3 Answers 3

up vote 18 down vote accepted

You can shift your axes, ticks and labels to obtain the axis effect. Adjusting the color of the plot and the size of the marks, gets you closer to the general style. Labels may be added via nodes referencing points in the data coordinate system.

Sample output

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.9}

\pgfkeys{/pgfplots/x axis shift down/.style={
    x axis line style={yshift=-#1},
    xtick style={yshift=-#1},
    xticklabel shift={#1}}}
\pgfkeys{/pgfplots/y axis shift left/.style={
    y axis line style={xshift=-#1},
    ytick style={xshift=-#1},
    yticklabel shift={#1}}}

\begin{document}
\begin{tikzpicture}[every pin/.style={red!50!black,font=\small\sffamily}]
  \begin{axis}[xlabel={$L$ [H]},
    ylabel={$\hat{I}_{DM}$ [A]},
    separate axis lines,
    axis x line*=bottom,
    x axis shift down=10pt,
    enlarge x limits=false,
    axis y line*=left,
    y axis shift left=15pt,
    xtick=data,
    ytick={0.4,0.6,...,1.801},
    ymin=0.4,ymax=1.8]
  \addplot[black,mark=*,mark size=1.5pt] coordinates{(948e-6,1.61981) (1.5e-3,1.02377)
  (2e-3,0.769047) (2.5e-3,0.614994) (3e-3,0.503511)}; 
  \node[coordinate,pin=above right:{2007}] at (axis cs:1.5e-3,1.02377) {};
\end{axis}
\end{tikzpicture}
\end{document}

(The last ytick value is 1.801 instead of 1.8 because of rounding problems in the internal arithmetic.)

To adjust the thickness of the ticks, you can issue:

\pgfplotsset{every axis/.append style={semithick,tick style={major tick
length=4pt,semithick,black}}}

before the tikzpicture. Note that the ticks at the end of the axis are by default half the width of the others, so making them too thick will give a bad visual appearance. Making them all of equal width seems to be non-trivial, the coding being buried in the internals of pgfplots. Update Christian Feuersänger points out a solution to this is provided in a comment to How to make the tick thickness as the axis line?. A full example in the current case would then be:

Sample output

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=1.10}

\makeatletter
\def\pgfplots@drawticklines@INSTALLCLIP@onorientedsurf#1{}% 
\def\pgfplots@drawgridlines@INSTALLCLIP@onorientedsurf#1{}%
\makeatother

\pgfplotsset{every axis/.append style={semithick,tick style={major tick
length=4pt,semithick,black}}}

\pgfkeys{/pgfplots/x axis shift down/.style={
    x axis line style={yshift=-#1},
    xtick style={yshift=-#1},
    xticklabel shift={#1}}}
\pgfkeys{/pgfplots/y axis shift left/.style={
    y axis line style={xshift=-#1},
    ytick style={xshift=-#1},
    yticklabel shift={#1}}}

\begin{document}
\begin{tikzpicture}[every pin/.style={red!50!black,font=\small\sffamily}]
  \begin{axis}[xlabel={$L$ [H]},
    ylabel={$\hat{I}_{DM}$ [A]},
    separate axis lines,
    axis x line*=bottom,
    x axis shift down=10pt,
    enlarge x limits=false,
    axis y line*=left,
    y axis shift left=15pt,
    xtick=data,
    ytick={0.4,0.6,...,1.801},
    ymin=0.4,ymax=1.8]
  \addplot[black,mark=*,mark size=1.5pt] coordinates{(948e-6,1.61981) (1.5e-3,1.02377)
  (2e-3,0.769047) (2.5e-3,0.614994) (3e-3,0.503511)}; 
  \node[coordinate,pin=above right:{2007}] at (axis cs:1.5e-3,1.02377) {};
\end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
    
@GonzaloMedina Thanks. I have now added some styling in this direction. I chose to do this without loading the extra color names. –  Andrew Swann Jan 21 at 15:17
    
Any option to get the "tick lines" same as the axis lines ? –  s__C Jan 21 at 16:00
    
@s__C Code added at end. –  Andrew Swann Jan 22 at 20:12
    
I think if you test it with scaled y ticks=base 10:2 you'll see the 10^-2 is badly positioned. Any fix? –  s__C Jan 24 at 9:29
    
@s__C You can add every y tick scale label/.append style={xshift=-#1} to the definition of the y axis shift left/.style. –  Andrew Swann Jan 26 at 13:09

In addition to shifting the axis, you can go one step further and create what Tufte calls "range frames", where the axis lines only cover the range of the data. One way of doing this is described in Creating Tufte-style bar charts and scatterplots using PGFPlots in TUGBoat issue 34 :

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}

\makeatletter
\def\pgfplotsdataxmin{\pgfplots@data@xmin}
\def\pgfplotsdataxmax{\pgfplots@data@xmax}
\def\pgfplotsdataymin{\pgfplots@data@ymin}
\def\pgfplotsdataymax{\pgfplots@data@ymax}
\makeatother

\pgfplotsset{
    range frame/.style={
        tick align=outside,
        axis line style={opacity=0},
        after end axis/.code={
            \draw ({rel axis cs:0,0}-|{axis cs:\pgfplotsdataxmin,0}) -- ({rel axis cs:0,0}-|{axis cs:\pgfplotsdataxmax,0});
            \draw ({rel axis cs:0,0}|-{axis cs:0,\pgfplotsdataymin}) -- ({rel axis cs:0,0}|-{axis cs:0,\pgfplotsdataymax});
        }
    }
}

\begin{tikzpicture}
\begin{axis}[
    range frame,
    xlabel={$L$ [H]},
    ylabel={$\hat{I}_{DM}$ [A]},
    axis lines*=left,
    xtick=data, ymin=0.41
]
  \addplot +[black, mark options=fill=black] coordinates {(948e-6,1.61981) (1.5e-3,1.02377) (2e-3,0.769047) (2.5e-3,0.614994) (3e-3,0.503511)};
\end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
    
In my code, if you just specify enlarge y limits=false instead of yticks, ymax, ymin you get the same output. –  Andrew Swann Jan 21 at 14:25
    
@AndrewSwann: Good point! –  Jake Jan 21 at 14:31
    
I tried to use all the solutions. This one is working except for one point: the axis line style={opacity=0} seems to have no effect, therefore masking the frame. –  Alessandro Cuttin Sep 14 at 8:27
    
@AlessandroCuttin: What version of TikZ and PGFPlots are you using? –  Jake Sep 14 at 10:38
    
Package: tikz 2013/12/13 v3.0.0 (rcs-revision 1.142) Package: pgfplots 2014/02/28 v1.10 Data Visualization (1.10-2-gb39fe75) I recently updated to TeXlive 2014 –  Alessandro Cuttin Sep 14 at 10:49

Pgfplots allows a very fine axis customization thanks to options like:

  • x/y/z axis line style
  • x/y/ztick style
  • x/yt/zticklabel style

Basically, if you shift elements in a proper manner, you can achieve something similar. An humble attempt intended as proof of concept:

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}

\begin{document}
\begin{tikzpicture}[font=\sffamily]
\begin{axis}[extra description/.code={% to place xlabel and ylabel more arbitrarily
  \node[below=7pt] at ([xshift=1.5cm]xticklabel* cs:1){$L$ [H]};
  \node at ([xshift=-1.5cm]yticklabel* cs:0.5){$\hat{I}_{DM}$ [A]};
  },
  axis x line=left,
  axis y line=left,
  y axis line style={xshift=-6pt,-},
  x axis line style={yshift=-6pt,-},
  xtick style={yshift=-4pt,black}, % black to override the default style
  ytick style={xshift=-4pt,black}, % black to override the default style
  xticklabel style={yshift=-5pt},
  yticklabel style={xshift=-5pt},  
  scaled ticks=false,
  ymin=0.5,
  ymax=1.75,
  ytick={0.5,0.75,1,1.25,1.5,1.75},
  yticklabels={0.5,0.75,1,1.25,1.5,1.75},
  xmin=0.9e-3,
  xmax=3.2e-3,
  xtick={0.9e-3,1.4e-3,2e-3,2.6e-3,3.2e-3},
  xticklabels={0.9e-3,1.4e-3,2e-3,2.6e-3,3.2e-3}]
  \addplot coordinates {(948e-6,1.61981) (1.5e-3,1.02377) (2e-3,0.769047) (2.5e-3,0.614994) (3e-3,0.503511)};
\end{axis}
\end{tikzpicture}
\end{document}

The result:

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.