尝试制作自动直方图(在 pgfplots 中?)

尝试制作自动直方图(在 pgfplots 中?)

如何将宏生成的自动表格转换为自动直方图?最好的方法是使用 吗pgfplots

\documentclass{article}

\RequirePackage{ifthen}
\RequirePackage{siunitx}
\RequirePackage{booktabs}
\RequirePackage{xparse}

% **********************************************************
\ExplSyntaxOn
% **********************************************************

\tl_const:Nx \c_aw_the_alphabet_tl {abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,.;?()!' \token_to_str:N :}

\tl_new:N \l_aw_tab_rows_tl
\seq_new:N \g_aw_theor_rats_seq
\seq_new:N \g_aw_the_alphabet_seq

\seq_gset_split:Nnn \g_aw_theor_rats_seq {,}
{0.0651738,0.0124248,0.0217339,0.0349835,0.1041442,0.0197881,0.0158610,0.0492888,0.0558094,0.0009033,0.0050529,0.0331490,0.0202124,0.0564513,0.0596302,0.0137645,0.0008606,0.0497563,0.0515760,0.0729357,0.0225134,0.0082903,0.0171272,0.0013692,0.0145984,0.0007836,0.1918182}


\NewDocumentCommand {\showtable}{}
    {
      \clearpage
      \thispagestyle{empty}
      \aw_make_table:
    }

\cs_generate_variant:Nn \seq_set_split:Nnn {NnV}
\cs_new:Npn \aw_make_table:
    {
      \seq_set_split:NnV \g_aw_the_alphabet_seq {} \c_aw_the_alphabet_tl
      %takes corresponding letter/theoretical ratio pairs from sequences and applies function
      \seq_mapthread_function:NNN \g_aw_the_alphabet_seq \g_aw_theor_rats_seq \aw_generate_row:nn
    \begin{table}
        \centering
        \footnotesize
      \begin{tabular}{cS}
        \toprule
        {Letter}&{Actual}\\
        \midrule
        \textvisiblespace&1\%\\
        \tl_use:N \l_aw_tab_rows_tl
        \bottomrule
      \end{tabular}\par
    \end{table}
    }

\cs_new:Npn \aw_generate_row:nn #1#2
    {
      \tl_put_right:Nn \l_aw_tab_rows_tl {#1&}
      \tl_put_right:Nn \l_aw_tab_rows_tl {\fp_eval:n{100*{#2}}\%}
      \tl_put_right:Nn \l_aw_tab_rows_tl {\\}
    }

% **********************************************************
\ExplSyntaxOff
% **********************************************************

\begin{document}

\showtable{}

\end{document}

我尝试过这种方法但出现了一些错误:

...

\usepackage{pgfplots}

\pgfplotsset{%
            /pgf/number format/use comma,%
            compat=newest}

... 

\begin{figure}
\centering
  \begin{tikzpicture}
    \begin{axis}
    \addplot coordinates{%
                        (\textvisiblespace,1)
                        \tl_use:N \l_aw_tab_rows_tl%
                        };
    \end{axis}
  \end{tikzpicture}
\caption{histogram.}
\end{figure}

...

\cs_new:Npn \aw_generate_row:n #1
    {
       \tl_put_right:Nn \l_aw_tab_rows_tl {(#1,}
      \tl_put_right:Nn \l_aw_tab_rows_tl {\fp_eval:n{100*{#2}})}
    }

...

相关内容