0

I'm trying to make a lot of different variations of PGFplots label styles so I'm trying to define different values and use \ticknum to pick one of them for example

\newcommand{\x0}{0.3}
\newcommand{\x1}{0.5}
\newcommand{\x2}{0.7}

...

every x tick label/.style={
    rotate=45,anchor=north east, text opacity=\x\ticknum,
},

But this gives me this error every time

! Undefined control sequence.\tikz@textopacity ->\x\ticknum \end{axis}

If this succeeds I also want to define different variables to change rotate value for every x tick differently for example. How can I make this to work?

EDIT : This is what works like a charm with colors but I'm trying to make something like this to work with numeric values as well.

\definecolor{col0}{RGB}{0,0,255}
\definecolor{col1}{RGB}{255,0,0}
\definecolor{col2}{RGB}{0,255,0}

...

every extra x tick/.style={
    grid=none, 
    tick label style={draw=col\ticknum},
},

This is a complete code

\documentclass{article}
\usepackage[a4paper,tmargin=5cm,bmargin=0cm,lmargin=0cm,rmargin=0.2cm,footskip=0cm]{geometry}
\usepackage{graphicx}
\usepackage{pgfplots}
\usepackage{adjustbox}
\pgfplotsset{compat=1.8}
\usepgfplotslibrary{groupplots}

\begin{document}



\begin{adjustbox}{center}
\begin{tikzpicture}
\definecolor{COL0}{RGB}{255,0,0}
\definecolor{COL1}{RGB}{0,255,0}
\newcommand{\x0}{1}
\newcommand{\x1}{1}
\begin{axis}[
    /pgfplots/ymin=0,
    height=10cm,width=20cm,
    ybar stacked,
    /pgf/bar width=0.952381cm,           
    legend style={at={(0.5,0.98)},
      anchor=north,legend columns=-1,font=\Large},
    symbolic x coords={1,2},
    xtick=data,
    x=1.14286cm,                           
    enlarge x limits={abs=0.666667cm},  
    every x tick label/.style={
        rotate=45,anchor=north east, text opacity=1, inner sep=5pt    %\x\ticknum (trying make this to work)
    },
    xticklabels={Text A,},
    every extra x tick/.style={
        grid=none, 
        tick label style={draw=COL\ticknum},    %Here this works 
    },
    extra x ticks={2},
    extra x tick labels={Text Extra},
    ]

\addplot+[fill=COL0,ybar] plot coordinates {(1,0.00519089)(2,0.0850676)};
\addplot+[fill=COL1,ybar] plot coordinates {(1,1.74808)(2,1.06387)};
\legend{\strut A,\strut B}

\end{axis}
\end{tikzpicture}
\end{adjustbox}
\end{document}
6
  • 2
    You can't define commands with a digit after letters in their name. And you can't call the command \foo as \f\oo even if you do \newcommand{\f}{f}\newcommand{\oo}{oo}.
    – egreg
    Commented Oct 3, 2020 at 22:06
  • Is there other way to define variables and use together with \ticknum? @egreg
    – etrusks
    Commented Oct 3, 2020 at 22:07
  • Please, make a minimal (but complete) example.
    – egreg
    Commented Oct 3, 2020 at 22:08
  • Look at my edit, thats what im trying to do but with numeric values instead of colors @egreg
    – etrusks
    Commented Oct 3, 2020 at 22:11
  • The fact it works with colors is not relevant; what I asked for is a complete code, at least of the tikzpicture you want to draw.
    – egreg
    Commented Oct 3, 2020 at 22:15

1 Answer 1

0

I figured out a workaround so I don't have to specify opacity. I'm just making every label as extra label and then do this and specifying different color for every characteristic

\definecolor{FILL0}{RGB}{255,255,255}
\definecolor{FILL1}{RGB}{255,0,0}

\definecolor{DRAW0}{RGB}{255,255,255}
\definecolor{DRAW1}{RGB}{128,255,50}

\definecolor{TEXT0}{RGB}{255,128,128}
\definecolor{TEXT1}{RGB}{128,255,128}

every extra x tick/.style={    
    grid=none,
    tick label style={fill=FILL\ticknum, draw=DRAW\ticknum,  text=TEXT\ticknum},     
},

This way I can pick colors that look like it has opacity 0.5 for example. So instead of making text black with opacity 0.5 I'm making text greyish with opacity 1. No one sees the difference

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .