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.

The new Mathematica 9 is out! I would love to know how to make similar plots to the one's advertized, particularly the following:

plot with lines from x-axis each point and a plot with changing colors after specific point

Here is a simple plot to get started.

%& -shell-escape
\documentclass{article}
\usepackage{tikz}

\begin{filecontents}{data.dat}
3.045784        3.415896
3.405784        4.025693
3.785784        4.522530
4.125784        5.538449
4.485784        6.704992
4.805784        6.978939
5.145784        7.113496
5.425784        8.916397
6.065784        9.487712
6.365784        10.876397
6.685784        10.693497
7.025784        11.364131
7.345784        11.442530
7.665784        12.582530
8.005784        13.125693
8.225784        13.738450
8.585784        14.247891
8.865784        14.982530
\end{filecontents}

\begin{document}
\pagestyle{empty}

\begin{tikzpicture}[x=1cm,y=0.4cm]

  \def\xmin{3}
  \def\xmax{9.2}
  \def\ymin{2}
  \def\ymax{15.5}

  % grid
  \draw[style=help lines, ystep=2, xstep=1] (\xmin,\ymin) grid
  (\xmax,\ymax);

  % axes
  \draw[->] (\xmin,\ymin) -- (\xmax,\ymin) node[right] {$x$};
  \draw[->] (\xmin,\ymin) -- (\xmin,\ymax) node[above] {$y$};

  % xticks and yticks
  \foreach \x in {3,4,...,9}
    \node at (\x, \ymin) [below] {\x};
  \foreach \y in {2,4,...,14}
    \node at (\xmin,\y) [left] {\y};

  % plot the data from the file data.dat
  % smooth the curve and mark the data point with a dot
  \draw[color=blue] plot[smooth,mark=*,mark size=1pt] file {data.dat}
   node [right] {data};


\end{tikzpicture}

\end{document}

simple plot example

share|improve this question
3  
Congrats by the way for a nice graph without pgfplots I was looking for the start of the axis environment :) –  percusse Nov 29 '12 at 20:04
add comment

3 Answers

up vote 25 down vote accepted

Here's a way of doing this with PGFPlots: The first plot is simply a ycomb plot, and the second I would draw using separate plots for the areas (with a trailing \closedcycle to get the filling right) and the lines.

\documentclass{article}
\usepackage{pgfplots}
\usepackage{filecontents}

\begin{filecontents}{data.dat}
3.045784        3.415896
3.405784        4.025693
3.785784        4.522530
4.125784        5.538449
4.485784        6.704992
4.805784        6.978939
5.145784        7.113496
5.425784        8.916397
6.065784        9.487712
6.365784        10.876397
6.685784        10.693497
7.025784        11.364131
7.345784        11.442530
7.665784        12.582530
8.005784        13.125693
8.225784        13.738450
8.585784        14.247891
8.865784        14.982530
\end{filecontents}

\begin{document}
\pgfplotsset{
    compat=1.5,
    width=10cm,
    height=5cm
}


\begin{tikzpicture}
\begin{axis}[
    ymin=0,
    xtick=\empty,
    ytick=\empty,
    axis background/.style={fill=gray!10},
]
\addplot [ycomb, red, very thick, mark=*, mark options={red!60!black}] table {data.dat};
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[
    ymin=0,
    xtick=\empty,
    ytick=\empty,
    axis background/.style={fill=gray!10},
    enlarge x limits=false
]
\addplot [draw=none, fill=orange!40!yellow] table {data.dat} \closedcycle;
\addplot [draw=gray, very thick] table {data.dat};

\addplot [draw=none, fill=red!60] table [
    x expr=\thisrowno{0}+8.865784-3.045784,
    y expr=\thisrowno{1}+14.982530-3.415896
] {data.dat} \closedcycle;
\addplot [draw=red!70!black, very thick] table [
    x expr=\thisrowno{0}+8.865784-3.045784,
    y expr=\thisrowno{1}+14.982530-3.415896
] {data.dat};
\end{axis}
\end{tikzpicture}

\end{document}
share|improve this answer
add comment

Aha, Jake was way faster.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
enlargelimits=false,
axis background/.style={shade,top color=gray!20,bottom color=white},
]
\addplot[ycomb,mark=*,mark color=black,domain=2:10,samples=70] {rnd+(x)^0.3333};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[
ymax=7,
axis background/.style={shade,top color=gray!20,bottom color=white},
]
\addplot[fill=orange,no marks,samples=500,domain=1.5:10] {rnd+ln(x)} \closedcycle;
\addplot[fill=brown,no marks,samples=100,domain=10:12] {0.5*rnd+ln(x)} \closedcycle;
\draw node[append after command={ (a) -| (axis cs:11,2)}] (a) at (axis cs:6,4) {Global Filtering!};
\end{axis}

\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer
add comment

To begin with, I would recommend moving your example to use pgfplots, and then work it out.

$1000 cheaper you get this (code below)enter image description here

\documentclass{article}
\usepackage{pgfplots}
\usepackage{filecontents}
\begin{filecontents}{data.dat}
3.045784        3.415896
3.405784        4.025693
3.785784        4.522530
4.125784        5.538449
4.485784        6.704992
4.805784        6.978939
5.145784        7.113496
5.425784        8.916397
6.065784        9.487712
6.365784        10.876397
6.685784        10.693497
7.025784        11.364131
7.345784        11.442530
7.665784        12.582530
8.005784        13.125693
8.225784        13.738450
8.585784        14.247891
8.865784        14.982530
\end{filecontents}

\begin{document}
\pagestyle{empty}
\begin{tikzpicture}[x=1cm,y=0.4cm]
\begin{axis}
\addplot+[ycomb] table {data.dat};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}[x=1cm,y=0.4cm]
\begin{axis}
\addplot+[fill=orange, opacity=0.5,mark=none] table {data.dat} \closedcycle;
\end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
add comment

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.