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.

My document contains a lot of colored PGFPlots, which are generated from external data files. In order to save costs when printing, I would like to automatically convert the color of every PGFPlot in the appendix to grayscale, so that I can switch around graphics from the body part and the appendix with the color adjusting automatically.

I found a couple of posts on how to automatically convert PDFs or included graphics to grayscale, but sadly no information on how to do the same with PGFPlots. In order to indicate what I mean, I have prepared a comparably long MWE, which is quite close to my real code:

mwe.tex:

\documentclass[12pt,a4paper]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage[usenames,dvipsnames,svgnames,x11names]{xcolor}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.9}

\usepackage{adjustbox}
\usepackage{float}
\floatstyle{boxed}
\restylefloat{figure}
\floatplacement{figure}{htb!}
\usepackage{placeins}

\usepackage{lipsum}

\begin{document}
    \section{Introduction}
    \lipsum[1]

    \section{Body}
    \lipsum[2]

    \begin{figure}
        \begin{adjustbox}{max width=\textwidth,max height=\textheight}
            \begin{tikzpicture}
                \begin{groupplot}[ybar=0pt,/pgf/bar width=1,ymin=0,xmin=0.5,xmax=5.5,width=\textwidth,group style={group size=1 by 2,xticklabels at=edge bottom,yticklabels at=edge left,vertical sep=18pt},ylabel style={rotate=-90,text width=1.8cm,align=right},axis x line*=left,point meta=explicit symbolic,every node near coord/.append style={font=\small},nodes near coords={\ifnum\pgfplotspointmeta>0 \pgfplotspointmeta\fi},cycle list={fill=gray!50,draw=black}]
                \nextgroupplot [ymax=14,y=1.5mm,try min ticks=2,ylabel={Foo's Bar'ed}]
                \addplot +[fill=green!50] table [y index=1, meta index=1] {mwe.dat};
                \nextgroupplot [ymax=14,y=1.5mm,try min ticks=2,ylabel={Bar's Foo'ed}]
                \addplot +[fill=orange!50] table [y index=2, meta index=2] {mwe.dat};
                \end{groupplot}
            \end{tikzpicture}
        \end{adjustbox}
        \caption{Colored Figure}
    \end{figure}

    \lipsum[3]
    \FloatBarrier

    \section{Appendix}
    \lipsum[4]

    \begin{figure}
        \begin{adjustbox}{max width=\textwidth,max height=\textheight}
            \begin{tikzpicture}
                \begin{groupplot}[ybar=0pt,/pgf/bar width=1,ymin=0,xmin=0.5,xmax=5.5,width=\textwidth,group style={group size=1 by 2,xticklabels at=edge bottom,yticklabels at=edge left,vertical sep=18pt},ylabel style={rotate=-90,text width=1.8cm,align=right},axis x line*=left,point meta=explicit symbolic,every node near coord/.append style={font=\small},nodes near coords={\ifnum\pgfplotspointmeta>0 \pgfplotspointmeta\fi},cycle list={fill=gray!50,draw=black}]
                \nextgroupplot [ymax=14,y=1.5mm,try min ticks=2,ylabel={Foo's Bar'ed}]
                \addplot +[fill=green!50] table [y index=1, meta index=1] {mwe.dat};
                \nextgroupplot [ymax=14,y=1.5mm,try min ticks=2,ylabel={Bar's Foo'ed}]
                \addplot +[fill=orange!50] table [y index=2, meta index=2] {mwe.dat};
                \end{groupplot}
            \end{tikzpicture}
        \end{adjustbox}
        \caption{Grayscale Figure}
    \end{figure}
\end{document}

mwe.dat:

Day FooBar BarFoo 
1   2      1      
2   1      0      
3   1      0      
4   3      1      
5   5      1        

Screenshot of MWE Page 1 Screenshot of MWE Page 2

share|improve this question
1  
You can select a different cycle list involving only grays for the appendix graphics in pgfplots. –  percusse Mar 30 at 10:40

1 Answer 1

up vote 8 down vote accepted

You can simply include \selectcolormodel{gray} when starting the appendix.

The code (included the mwe.dat as filecontents):

\documentclass[12pt,a4paper]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage[usenames,dvipsnames,svgnames,x11names]{xcolor}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.9}

\usepackage{adjustbox}
\usepackage{float}
\floatstyle{boxed}
\restylefloat{figure}
\floatplacement{figure}{htb!}
\usepackage{placeins}
\usepackage{filecontents}
\usepackage{lipsum}

\begin{filecontents*}{mwe.dat}
Day FooBar BarFoo 
1   2      1      
2   1      0      
3   1      0      
4   3      1      
5   5      1   
\end{filecontents*}

\begin{document}
    \section{Introduction}
    \lipsum[1]

    \section{Body}
    \lipsum[2]

    \begin{figure}
        \begin{adjustbox}{max width=\textwidth,max height=\textheight}
            \begin{tikzpicture}
                \begin{groupplot}[ybar=0pt,/pgf/bar width=1,ymin=0,xmin=0.5,xmax=5.5,width=\textwidth,group style={group size=1 by 2,xticklabels at=edge bottom,yticklabels at=edge left,vertical sep=18pt},ylabel style={rotate=-90,text width=1.8cm,align=right},axis x line*=left,point meta=explicit symbolic,every node near coord/.append style={font=\small},nodes near coords={\ifnum\pgfplotspointmeta>0 \pgfplotspointmeta\fi},cycle list={fill=gray!50,draw=black}]
                \nextgroupplot [ymax=14,y=1.5mm,try min ticks=2,ylabel={Foo's Bar'ed}]
                \addplot +[fill=green!50] table [y index=1, meta index=1] {mwe.dat};
                \nextgroupplot [ymax=14,y=1.5mm,try min ticks=2,ylabel={Bar's Foo'ed}]
                \addplot +[fill=orange!50] table [y index=2, meta index=2] {mwe.dat};
                \end{groupplot}
            \end{tikzpicture}
        \end{adjustbox}
        \caption{Colored Figure}
    \end{figure}

    \lipsum[3]
    \FloatBarrier

    \section{Appendix}
    \selectcolormodel{gray}
    \lipsum[4]

    \begin{figure}
        \begin{adjustbox}{max width=\textwidth,max height=\textheight}
            \begin{tikzpicture}
                \begin{groupplot}[ybar=0pt,/pgf/bar width=1,ymin=0,xmin=0.5,xmax=5.5,width=\textwidth,group style={group size=1 by 2,xticklabels at=edge bottom,yticklabels at=edge left,vertical sep=18pt},ylabel style={rotate=-90,text width=1.8cm,align=right},axis x line*=left,point meta=explicit symbolic,every node near coord/.append style={font=\small},nodes near coords={\ifnum\pgfplotspointmeta>0 \pgfplotspointmeta\fi},cycle list={fill=gray!50,draw=black}]
                \nextgroupplot [ymax=14,y=1.5mm,try min ticks=2,ylabel={Foo's Bar'ed}]
                \addplot +[fill=green!50] table [y index=1, meta index=1] {mwe.dat};
                \nextgroupplot [ymax=14,y=1.5mm,try min ticks=2,ylabel={Bar's Foo'ed}]
                \addplot +[fill=orange!50] table [y index=2, meta index=2] {mwe.dat};
                \end{groupplot}
            \end{tikzpicture}
        \end{adjustbox}
        \caption{Grayscale Figure}
    \end{figure}
\end{document}

This gives the output

First page Second page

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.