1

For some reason, the parameter fixed in my style textnumber is ignored when used as a parameter to \addplot.

Output

Note how the x labels are written in scientific notation despite the parameter definition containing fixed. enter image description here

Code

\documentclass{article}
\usepackage{fontspec}
\usepackage{tikz,pgfplots,pgfplotstable,fancyvrb,environ,verbatim}
\usepackage{xparse}

% For the sake of aesthetics, define some colors that are not ugly
\definecolor{amber}{rgb}{1.0, 0.49, 0.0}
\definecolor{bleudefrance}{rgb}{0.19, 0.55, 0.91}
\tikzset{
  style-addplot-color1/.style={draw=none,fill=bleudefrance},
  style-addplot-color2/.style={draw=none,fill=amber},
}% \addplot style, bar format

% Define a bar chart
\pgfplotsset{horizontalbarchartstyle/.style={
 % symbolic y coords=,% set dict of expected textual y coordinates, we avoid this dup of data by using "yticklabels from table" and "ytick=data"
  axis lines*=left,
  y=12mm,% vertical spacing (define the length of a unit in the y direction )
  xbar={1pt},
  bar width=4mm,% bar thickness
  y axis line style = { opacity = 0 },
  x axis line style = { black!35 },
  width=.6\textwidth,% width of chart itself, does not include tick labels
  xminorgrids,
  xlabel={}, % optional label below x axis but useless in global style
  xmin=0,
  xmax=100,
  xtick={0,100,...,100},
  minor xtick={25,50,...,75},
  point meta={x},
  every node near coord/.append style={font=\bfseries},
  nodes near coords align={horizontal},% alignment of "nodes near coords"
  enlarge y limits={abs=10mm},% add space above and below bars
  yticklabels from table={\datatable}{0}, % necessary for pgfplotstableread data
  ytick=data,
  xticklabel={\pgfmathprintnumber[textnumber]{\tick}}, % disable math mode
  x tick label style={font=\footnotesize,black!35},
  y tick style={opacity=0},
  y tick label style={font=\raggedright\small,color=black!65,align=right,text width=.4\textwidth},
  legend style={font=\footnotesize},
  label style={font=\footnotesize},
  minor grid style={dotted,black!65},
  },
}

% Define text used in bar chart
\pgfplotsset{
  /pgf/number format/textnumber/.style={
    fixed,% no scientific notation
    assume math mode=true,
    set thousands separator={},
    },
}

% Define user level/document level environment
\NewDocumentEnvironment{horizontaldualbarchart}{ m m } % #1: sollmax #2: istmax
{\par\noindent\ignorespaces\VerbatimOut{\jobname-horizontalbarchart.tmp}}%begin
  {\endVerbatimOut
  % Inject BODY into pgfplotstableread
  \pgfplotstableread[col sep=comma, 
header=false]{\jobname-horizontalbarchart.tmp}{\datatable}
  % Use \datatable for plot data
  \begin{tikzpicture}
   \begin{axis}[horizontalbarchartstyle,xmax=#2,xtick={0,#1,#2},minor xtick={#1}]
     \addplot [style-addplot-color2, nodes near coords={\color{amber}\pgfmathprintnumber[textnumber]{\pgfplotspointmeta}}] table [col sep=comma, y expr=\coordindex, x index=2] {\datatable};
     \addplot [style-addplot-color1, nodes near coords={\color{bleudefrance}\pgfmathprintnumber[textnumber]{\pgfplotspointmeta}}] table [col sep=comma, y expr=\coordindex, x index=1] {\datatable};
   \end{axis}
  \end{tikzpicture}\ignorespacesafterend
}%

\begin{document}

\begin{horizontaldualbarchart}{367200}{515700}
{Analysis}, 0, 0
{Creation of Information}, 20004, 415845
{Adaptions of Information}, 14400, 0
\end{horizontaldualbarchart}

\end{document}

1 Answer 1

2

You need

scaled x ticks=false

I'm guessing the scaling happens before the number is passed to xticklabel, so the values that \tick refers to are actually 3.67 and 5.16, not 3.67e5/5.16e5.

You must log in to answer this question.

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