绘制条形图(水平)或对数折线图

绘制条形图(水平)或对数折线图

我正在尝试绘制此图,一个是线性的,另一个是指数的,与数据的大小成比例。这些数字彼此相差太大,我不知道如何让它更容易理解。

是否可以将此条形图设为水平图或对数折线图?

\documentclass{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{textcomp}
\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.9}

\begin{document}

\begin{tikzpicture}
    \begin{axis}[
            x tick label style={
                /pgf/number format/1000 sep=},
            xlabel=AST nodes,
            ylabel=Time in seconds,
            enlargelimits=0.05,
            legend style={at={(0.5,-0.1)},
                anchor=north,legend columns=-1},
            ybar interval=0.7
        ]
        \addplot 
        coordinates {(3,0.009)(30,0.003)(111,0.005)(354,0.019)(1083,0.097)(3270,0.044)(9831,0.064)(29514,0.501)(88563,2.276)(265710,7.439)(797151,27.578)(2391474,128.611)};
        \addplot 
        coordinates {(3,0.091)(30,0.495)(111,2.789)(354,3.390)(1083,5.021)(3270,20.149)(9831,48.015)(29514,158.442)(88563,857.381)(265710,2693.862)(797151,8771.571)};
        \legend{Static scheduling,Demand Scheduling}
    \end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

这是源表: 在此处输入图片描述

\begin{figure}[htbp]
\begin{center}
\scalebox{0.9}{
\begin{tblr}
{
colspec      = {X[c,m]X[c,m]X[c,m]X[c,m]X[c,m]X[c,m]},
cell{1}{1}   = {r=2}{},
cell{1}{2}   = {r=2}{},
cell{1}{3,5} = {c=2}{},
cell{14}{5}  = {c=2}{},
hlines,
vlines,
}
AST depth & Nodes             & Visit sequence evaluation &  & Demand evaluation &    \\
& & ET in sec.                 & Memory in MB & ET in sec.                   & Memory in MB \\
1 & 3 & 0.009 & 2.971 & 0.091 & 7.741 \\ 
2 & 30 & 0.003 & 2.921 & 0.495 & 12.362 \\ 
3 & 111 & 0.005 & 3.646 & 2.789 & 21.288 \\ 
4 & 354 & 0.019 & 7.872 & 3.390 & 520.246 \\ 
5 & 1083 & 0.097 & 13.091 & 5.021 & 1016.131 \\ 
6 & 3270 & 0.044 & 46.332 & 20.149 & 1745.389 \\
7 & 9831 & 0.064 & 57.778 & 48.015 & 4564.360 \\ 
8 & 29514 & 0.501 & 155.338 & 158.442 & 7755.513 \\ 
9 & 88563 & 2.276 & 198.215 & 857.381 & 12081.491 \\ 
10 & 265710 & 7.439 & 940.484 & 2693.862 & 15053.265 \\ 
11 & 797151 & 27.578 & 1368.750 & 8771.571 & 15862.919 \\ 
12 & 2391474 & 128.611 & 3279.699 &  \text{JVM crashed}&   \\

\end{tblr}}
\end{center}
    \caption{Benchmarks of running \href{https://github.com/boyland/aps/blob/master/examples/nested-cycles.aps}{\texttt{nested-cycles}} example}
    \label{fig:nested-cycles-benchmark}
    The exponential nature of the demand schedule becomes evident as number of the AST nodes gets larger.
\end{figure}

答案1

我不确定你想在这里绘制什么:你有一组截然不同的数字,我不清楚哪些是独立变量。所以我将绘制内存使用量与深度的关系图,但我希望你可以很容易地将其适应其他场景。

我建议使用pgfplots,加载整个数据,然后探索不同的图表以找到一个能够表达您需求的图表。在下面的例子中,我用pgfplotstable(注意:nan表示“不是数字”,可用于表示缺失数据)将数据加载到内存中,然后以深度作为独立变量,以线性比例绘制两种方法的内存:

\documentclass[border=10pt]{standalone}
\usepackage[T1]{fontenc}
\usepackage{pgfplots}\pgfplotsset{compat=newest}
\usepackage{pgfplotstable}
\pgfplotstableread{
depth  Nodes    St       Sm        Dt        Dm
1      3        0.009    2.971     0.091     7.741
2      30       0.003    2.921     0.495     12.362
3      111      0.005    3.646     2.789     21.288
4      354      0.019    7.872     3.390     520.246
5      1083     0.097    13.091    5.021     1016.131
6      3270     0.044    46.332    20.149    1745.389
7      9831     0.064    57.778    48.015    4564.360
8      29514    0.501    155.338   158.442   7755.513
9      88563    2.276    198.215   857.381   12081.491
10     265710   7.439    940.484   2693.862  15053.265
11     797151   27.578   1368.750  8771.571  15862.919
12     2391474  128.611  3279.699  nan       nan
}\data
\begin{document}
\begin{tikzpicture}[]
    \begin{axis}[
        axis line style = {thick, gray},
        enlarge x limits,
        enlarge y limits,
        xlabel = {Depth},
        % every axis x label/.append style = {below, gray},
        ylabel = {memory (MB)},
        legend style = {nodes={right, font=\scriptsize},
            at={(0.05,0.6)}, anchor=west},
        clip mode = individual,
        ]
        \addplot table[x=depth, y=Sm]{\data};
        \addplot table[x=depth, y=Dm]{\data};
        \legend{Static memory, Dynamic memory}
    \end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

...数字和标签的格式等细节可以稍后调整。也许对数 y 轴更好?添加

 ymode = log,

(并调整图例位置0.05, 0.9),您得到:

在此处输入图片描述

也许你还想添加每次运行的节点数以及有关崩溃的信息。这有点复杂,我不得不在这个网站上搜索了一下,在 Ti 的手册中Z,以及pgfplots/pgfplotstable的那些,但有一个提议是:

\documentclass[border=10pt]{standalone}
\usepackage[T1]{fontenc}
\usepackage{pgfplots}\pgfplotsset{compat=newest}
\usetikzlibrary{shapes.symbols}% for starburst
\usepackage{pgfplotstable}
\pgfplotstableread{
depth  Nodes    St       Sm        Dt        Dm
1      3        0.009    2.971     0.091     7.741
2      30       0.003    2.921     0.495     12.362
3      111      0.005    3.646     2.789     21.288
4      354      0.019    7.872     3.390     520.246
5      1083     0.097    13.091    5.021     1016.131
6      3270     0.044    46.332    20.149    1745.389
7      9831     0.064    57.778    48.015    4564.360
8      29514    0.501    155.338   158.442   7755.513
9      88563    2.276    198.215   857.381   12081.491
10     265710   7.439    940.484   2693.862  15053.265
11     797151   27.578   1368.750  8771.571  15862.919
12     2391474  128.611  3279.699  nan       nan
}\data
\begin{document}
\begin{tikzpicture}[
    slanted blocks/.style={
        draw, fill=white, font=\tiny\ttfamily, rotate=45,
        anchor=south west, inner sep=2pt
    }]
    \begin{axis}[
        axis line style = {thick, gray},
        ymode = log,
        ymin = .2,
        xtick = {1,2,...,12},
        xlabel = {Depth},
        ylabel = {memory (MB)},
        legend style = {nodes={right, font=\scriptsize},
            at={(0.05,0.9)}, anchor=west},
        clip mode = individual,
        grid = major,
        ]
        \addplot table[x=depth, y=Sm]{\data};
        \addplot table[x=depth, y=Dm]{\data};
        \legend{Static memory, Dynamic memory}
        \pgfplotsinvokeforeach{0,...,11}{
            \node[slanted blocks] at ({#1+1},.2)
                {\pgfplotstablegetelem{#1}{Nodes}\of{\data}\pgfplotsretval};
        }
        \node[slanted blocks] at (0,.2) {\# of nodes};
        \node[starburst, fill=yellow, draw=red, thick, font=\tiny\ttfamily,
            inner sep=0pt, starburst point height=6pt]
            at (12, 2e4) {crash!};
    \end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

无论如何,我认为开始在 LaTeX 中编写情节,你应该得到例如gnuplot,或matlab,并尝试决定哪个绘制所需的图形,然后对其进行编码。

答案2

这是一种实现方法,无需花费太多时间进行细化(例如,可以突出显示 10 秒轴,或者可以将范围设置为相等,以显示巨大的差异;放置图例等):

在此处输入图片描述

因为您不知道我上次回答时如何赞扬我的解决方案,所以这里只是为您提供的起始代码,因此您可以声称自己取得了进展:

\documentclass[10pt,border=3mm,tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{datavisualization}

\begin{document}

 \begin{tikzpicture}
    \datavisualization[scientific axes,
...
    data{
        x,      y
...
    };
 \end{tikzpicture}
\end{document}

一些未完成的指示,您可以使用所述包的更多属性并放置两个节点和一条线来做什么:

结果2

相关内容