1

I am trying to create a 2D plot in which the x-label ticks are pictures, similar to what is posted here, with the difference that the images be created at the compile time in a parametric manner. The x-labels, which are graphics, are actually dependent on some input CSV file that determines the shape of the graphics. illustrated below just as an example. As can be seen, the arrows are my x labels are in different graphics. enter image description here

How should I approach this problem? I tried to define parameters needed such as

\newcommand{\PSI}{45}
\newcommand{\PHI}{45}

\newcommand{\cosPSI}{cos(\PSI)}
\newcommand{\sinPSI}{sin(\PSI)}
% These are just example to show my approach to this problem
% ...
\newcommand{\myFirstLabel}{\tikz \draw (0,0) -- (1,1);}

I also tried to use:

\newcommand{\myFirstLabel}{\begin{tikspicture} ...}

but the compiler complains about this. I wanted to see if I could have something like the following such that each new command create the graphical label using the parameters that I defined in the preamble.

xticklabels={\myLabel2, \myLabel2, ...}

Is this doable using LateX?

  • It would be helpful if you composed a fully compilable MWE including \documentclass and the appropriate packages that sets up the problem and at least works without the compile time customization. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. My recommendation would be to use a combination of \newcommand, \tikzset and possiblly pgfkeys (depending on the level of customization). – Peter Grill Jun 15 '16 at 5:42
1

It should work without any problems.

\documentclass[]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\begin{document}
\begin{tikzpicture}
\def\mylabel#1{\tikz\filldraw[#1] (0,0)circle (3mm);}
\begin{axis}[
xtick={-2,0,2},
xticklabels={\mylabel{red},\mylabel{blue},\mylabel{gray}}
]
\addplot {x};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

  • Thank you. The issue is when there are more complicated tiks codes inside mylabel. I am trying to use \begin{tikspicture} as the graphics for my labels, as the picture I have cannot be done by using one simple \draw command. – AFPP Jun 15 '16 at 6:37
  • @Ahmad shouldn't matter. Without your code we can't know the problem – percusse Jun 15 '16 at 6:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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