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.

Just after an hour spending browsing through the pgfplots manual, I am trying to have a figure and a table side by side (both the figure and the table use the same data). So I still have lot to learn!

So here is apples.dat file:

%Apples that went bad
year    value
2008    12053   %31 Dec 2007
2009    15792   %31 Dec 2008   
2010    22907   %31 Dec 2009  
2011    30997   %31 Dec 2010

And here are my plot commands:

\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}

\begin{document}

\pgfplotsset{width=7cm,height=5cm,compat=newest}
\begin{figure}[h]
\begin{tikzpicture}
\begin{axis}[
enlargelimits=false,
xmin=2008,
xmax=2012,
x tick label style={rotate=45,anchor=east},
mark=x,line width=1pt,
axis y line = none,
nodes near coords,
color=black,
grid=major
]
xlabel=year,
ylabel=value]
\addplot+ file[skip first = true,x=year,y=value,const plot mark right]{apples.dat};
\end{axis}
\end{tikzpicture}
\end{figure}
\pgfplotstabletypeset[columns={year,value}]{apples.dat}

\end{document} 

I am saving space by eliminating the y values and tick marks.

Questions:

  1. How to make the figure and the table appear side by side?

  2. If I need to rotate the two floats (figure and table) together at the same time and turn them 90 deg anticlockwise so that the appear in the landscape mode, how to proceed?

  3. I've tried using the const plot mark right option in \addplot but it doesn't work. Why?

  4. Why does the mark=x option doesn't work in my code?

  5. Why does the color=black option doesn't work in my code?

  6. If I want to output everything as an eps file. How to proceed? I have tried using

    \usepgfplotslibrary{external}
    \tikzexternalize% activate externalization!
    

but this doesn't work with the conventional LaTeX > dvips > ps2pdf route. So how to get an eps?

I am using TeXLive 2011 (with everything updated last week) on Win XP.

Thanks a lot...

share|improve this question
    
It may be better to divide this into several questions. For #1, see tex.stackexchange.com/questions/28666/… and tex.stackexchange.com/questions/6850/… –  Torbjørn T. Nov 24 '11 at 7:41
    
Thanks but for someone who knows pgfplots well, these should quite easy queries which will not take much space to answer. If I see that one or more queries is(are) giving problem(s) or need(s) a longer answer, then I will go for several posts. It depends on the feedback that I receive here. –  yCalleecharan Nov 24 '11 at 8:04
    
Yes, but your first two questions isn't really related to pgfplots at all. –  Torbjørn T. Nov 24 '11 at 8:11
    
But for the table, we use a command like \pgfplotstabletypeset which is part of pgfplotstable. I thought an elegant solution existed within pgfplots itself that can make the figure and table appear together. I will leave the queries like this for now and wait for some responses. If I need to create a separate post, I shall do it then. Thanks. –  yCalleecharan Nov 24 '11 at 8:17

1 Answer 1

up vote 4 down vote accepted
  1. Put both the plot and the table inside the figure environment. You can get a figure and a table caption if you load the caption package and use the \captionof{<type>}{<caption>} command.
  2. Enclose all the stuff in your figure environment in \rotatebox{90}{<...>}. You don't need to load additional packages if you're using TikZ.
  3. const plot mark right needs to be supplied to \addplot [<options>], not \addplot table [<options>].
  4. The same goes for mark=x. The correct syntax is \addplot [mark=x] table....
  5. color=black in the axis options works fine, but probably not as you expected. Try setting color=red in the axis options: The axis lines will be red. I assume you want all plots to be black (Hint: Don't say "Doesn't work", be specific!). For that, you need to add every axis plot post/.style={draw=black}, which will append the option to the \addplot options after everything else has been set, or specify color=black in the \addplot [<options>].
  6. No idea.

Bonus: For printing years, you would want to set x tick label style={/pgf/number format/.cd, use comma, 1000 sep={}}. Same goes for \pgfplotstabletypeset: Here, you can add

columns/year/.style={
        /pgf/number format/.cd,
        use comma,
        1000 sep={}
    }

\documentclass[12pt]{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{caption,subcaption}
\usepackage{filecontents}
\begin{filecontents}{apples.dat}
%Apples that went bad
year    value
2008    12053   %31 Dec 2007
2009    15792   %31 Dec 2008   
2010    22907   %31 Dec 2009  
2011    30997   %31 Dec 2010
\end{filecontents}

\begin{document}

\pgfplotsset{width=7cm,height=5cm,compat=newest}
\begin{figure}[h]

\begin{minipage}{0.45\textwidth}\centering
\begin{tikzpicture}
\begin{axis}[
enlargelimits=false,
xmin=2008,
xmax=2012,
x tick label style={
    yshift=-0.5ex,
    rotate=45,
    anchor=east,    
    /pgf/number format/.cd,
     use comma,
     1000 sep={}
},
line width=1pt,
axis y line = none,
nodes near coords,
every axis plot post/.style={color=black},
grid=major,
xlabel=year,
ylabel=value]
\addplot [mark=x,const plot mark right] file[skip first = true,x=year,y=value]{apples.dat};
\end{axis}
\end{tikzpicture}
\captionof{figure}{A pretty plot}
\end{minipage}
\begin{minipage}{0.45\textwidth}\centering
\captionof{table}{The data table}
\pgfplotstabletypeset[
    columns={year,value},
    columns/year/.style={
        /pgf/number format/.cd,
        use comma,
        1000 sep={}
    }]{apples.dat}
\end{minipage}
\end{figure}

\end{document} 
share|improve this answer
    
Thanks. I am using all latest versions of pgfplots and Tikz. And your code compiles fine also. Does \addplot [const plot mark right] table ... not suppose to draw horozontal lines with the points at the right of the interval? \addplot [mark=x] table... works now. And color = red is ok too. The way my code was written was not correct. 1 vote up. –  yCalleecharan Nov 24 '11 at 10:13
    
With color = red, the graph line and the markers turn red. But the axes remain black. –  yCalleecharan Nov 24 '11 at 10:18
    
@yCalleecharan: Ah, now I understand what you meant. You have to be careful where you supply your options: Plot options like mark=x or const plot mark right don't belong in the axis options directly, or in the table options, but either in the \addplot options or in every axis plot post/.style={...} –  Jake Nov 24 '11 at 11:27
    
Ok thanks for this clarification. –  yCalleecharan Nov 24 '11 at 11:47

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.