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.

I have a small problem with TikZ I can't figure out. I have some TikZ code generated in MATLAB (using matlab2tikz) showing an image with a user-defined colormap and the correspondent colorbar. The image is exported as .png but given that the colorbar is created in TikZ I need to color it accordingly (defining the new colormap). I simplified the code to get a MWE and it reads as follows (I replaced the user-defined colormap with a simple one):

\documentclass[11pt,twoside,a4paper]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pgfplotsset{plot coordinates/math parser=false}
\usepackage{tikz}                       %inline graphics
\usetikzlibrary{plotmarks,external}   
\begin{document}

\begin{tikzpicture}

\begin{axis}[width=\textwidth,height=4cm,axis on top,scale only axis,
xmin=0,xmax=5,xlabel={myxlabel},ymin=0,ymax=4000,
colorbar,
colormap ={mymap}{rgb(0pt)=(0,1,1); rgb(63pt)=(1,0,1)},
ylabel={myylabel}
]
\end{axis}
\end{tikzpicture}%
\end{document}

This works fine, but given that my colormap has more than two colors definitions, I thought that saving it in a separate .tex file, say mycmap.tex, was a nice idea

colormap ={mymap}{\input{mycmap}},

However, if I do this it doesn't work... I tried to save it as a .txt file instead of .tex, but still no luck. Any idea on how to fix it?

Thanks in advance! ;)

share|improve this question

2 Answers 2

I don't know why, but choosing colormaps with less than 64 colors worked for me.

share|improve this answer
    
Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. –  Martin Schröder Jan 7 at 11:11
1  
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post. –  Sigur Jan 7 at 12:28

You may define a macro in your external file as in the below code (filecontents package and environment used to create the external file):

\documentclass[11pt,twoside,a4paper]{article}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pgfplotsset{plot coordinates/math parser=false}
\usepackage{tikz}                       %inline graphics
\usetikzlibrary{plotmarks,external}

%% creation of external colormap
\usepackage{filecontents}
\begin{filecontents*}{\jobname-external-colormap}
\def\mycolormap{rgb(0pt)=(0,1,1); rgb(63pt)=(1,0,1)}
\end{filecontents*}
%%

\input{\jobname-external-colormap}

\begin{document}
\begin{tikzpicture}

\begin{axis}[width=\textwidth,height=4cm,axis on top,scale only axis,
xmin=0,xmax=5,xlabel={myxlabel},ymin=0,ymax=4000,
colorbar,
colormap ={mymap}{\mycolormap},
ylabel={myylabel}
]
\end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
    
Thanks for the reply Paul. I'm not really sure your solution solves my problem (which I had essentially forgotten :D), because my idea was including the colormap data from an external file. However, I've also discovered why I was getting problem when using more than 2 color points; the syntax I was using: colormap={mymap}{rgb(0pt)=(0,1,1);rgb(30pt)=(1,1,1); rgb(63pt)=(1,0,1)} doesn't work because I don't indicate the parameter [1pt] at the beginning of the color declaration. –  gbernardi Jan 8 at 12:18
    
It should instead be: colormap={mymap}{[1pt] rgb(0pt)=(0,1,1);rgb(30pt)=(1,1,1); rgb(63pt)=(1,0,1)} and like this it works even with more colours. –  gbernardi Jan 8 at 12:21
    
@gbernardi My example uses an external file (here, this external file is created by filecontents* environment to keep my code auto-sufficient). –  Paul Gaborit Jan 8 at 12:32
    
I see. Thanks for the clarification. –  gbernardi Jan 9 at 13:12

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.