输出

输出

由于某种原因,当用作 的参数时,fixed我的样式中的参数会被忽略。textnumber\addplot

输出

请注意,尽管参数定义包含,但 x 标签是以科学计数法书写的fixed在此处输入图片描述

代码

\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

你需要

scaled x ticks=false

我猜测缩放发生在数字传递给之前xticklabel,因此引用的值\tick实际上是 3.67 和 5.16,而不是 3.67e5/5.16e5。

相关内容