![如何在乳胶中绘制屋顶线图?](https://linux22.com/image/471630/%E5%A6%82%E4%BD%95%E5%9C%A8%E4%B9%B3%E8%83%B6%E4%B8%AD%E7%BB%98%E5%88%B6%E5%B1%8B%E9%A1%B6%E7%BA%BF%E5%9B%BE%EF%BC%9F.png)
我正在尝试在乳胶中找到一些屋顶线图的示例,但不幸的是,我找不到任何可以复制下面这个示例的东西。
屋顶线图:
我有的代码:
\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmode=log,
ymode=log,
xlabel={Operational Intensity (FLOPS/Byte)},
ylabel={Performance (FLOPS)},
grid=major,
xmin=0.01, xmax=100,
ymin=1, ymax=1000,
legend pos=north west,
]
% L1 Bandwidth Roofline
\addplot[name path=global, domain=0.01:1, red, thick] {x*1000} node[pos=0.6,anchor=south east] {L1 Bandwidth};
% L2 Bandwidth Roofline
\addplot[name path=l2, domain=0.01:2, blue, thick] {x*500} node[pos=0.5,anchor=south east] {L2 Bandwidth};
% L3 Bandwidth Roofline
\addplot[name path=l3, domain=0.01:10, green, thick] {x*200} node[pos=0.3,anchor=south east] {L3 Bandwidth};
% DRAM Bandwidth Roofline
\addplot[name path=dram, domain=0.01:100, orange, thick] {x*50} node[pos=0.1,anchor=south east] {DRAM Bandwidth};
% Compute Bound Roofline
\addplot[name path=compute, domain=1:100, black, thick] {100} node[pos=0.5,anchor=south] {Compute Bound};
% Shading under rooflines
\addplot[green!30] fill between[of=l3 and compute, soft clip={domain=0.01:10}];
\addplot[blue!30] fill between[of=l2 and l3, soft clip={domain=0.01:2}];
\addplot[red!30] fill between[of=global and l2, soft clip={domain=0.01:1}];
\addplot[orange!30] fill between[of=dram and global, soft clip={domain=0.01:100}];
% Example Kernel Performance Point
\addplot[mark=*, mark options={fill=black}, mark size=3pt] coordinates {(1,50)} node[anchor=south west] {Kernel A};
\end{axis}
\end{tikzpicture}
\end{document}
输出:
谁能帮我这个?
谢谢
答案1
这是一种简单的方法Tikz
。
评论:
此图未按比例缩放,因为它是
in absolute coordinates
。我认为您的草图是一个 15 厘米 x 4.5 厘米的矩形。所有位置都是估计的。代码以一系列相关内容开始
style-statements
:颜色相关,用于屋顶线、数据点及其标签。作为开发过程中的最后一步,我绘制了
shaded area
。为此, 很有用,即refactor some coordinates
在开始时说明它们,然后在以后使用时在代码中替换它们。要“绘制”,它必须是第一个。网格和框架没什么大不了的。
Labels
使用两个\foreach
循环。\i
用于进一步计算放置位置。对于 y 轴,节点必须是anchor=east
,因此它们看起来像是右边参差不齐。即坐标与右中间侧相关,而不是节点中心。先画
roof lines
垂直虚线。“曲线”只是几笔画。Data points
使用一个以圆形为形状并带有空文本的节点。这样,半径就通过最小节点尺寸来设置。labels
与那些数据点位置相关,如,(A)
但在极坐标中偏移。它们使用rounded corners
。紧接着是一条线,使用极坐标作为锚点。例如(AL.90)
,(AL.north)
而 (AL.60) 锚定在更靠右的位置。最后,放上峰值注释和轴文本。
\documentclass[10pt,border=3mm,tikz]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}[
% ~~~ colors ~~~~~~~~~~~~~~~~
grl/.style={gray!40},
ctl/.style={teal!50},
cbl/.style={fill=teal!15!blue!5,draw=none},
% ~~~ roof lines ~~~~~~~~~~~~~~~~~~
r1/.style={line width=1.5pt},
r2/.style={line width=1.5pt,ctl},
dev/.style={sloped,above,pos=.1,text=black},
l1/.style={dashed,line width=1.3pt},
l2/.style={l1,ctl},
% ~~~ data points and labels ~~~~~~~~~~~~~~
dp/.style={circle,fill=teal!60,draw=black},
lbl/.style={fill=white,rounded corners,draw},
shft/.style={shift=(203:8mm)},
shftu/.style={shift=(130:7mm)},
]
% ~~~ some coordinates from refactoring, for the shaded area ~~~~~~~
\coordinate (Z) at (6,4.2);
\coordinate (ZZ) at (0,1.8);
\coordinate (Y) at (6,0);
\coordinate (X) at (10.2,4.2);
\coordinate (W) at (10.2,0);
% ~~~ shaded area ~~~~~~~~
\draw[cbl] (ZZ) -- (Z) -- (X) -- (W) -- (0,0) -- cycle;
% ~~~ grid and frame ~~~~~~~~~
\draw[grl] (0,0) grid[xstep=5cm] ( 15,4.5);
\draw[line width=1.0pt] (0,0) rectangle (15,4.5);
% ~~~ labels ~~~~~~~~~~~
\foreach \x [count=\i] in {0.01, 0.1, 1, 10}
\node at (\i*5 - 5, -.3) {\x};
\foreach \y [count=\i] in {0.3, 1, 3, 10, 30}
\node[anchor=east] at (-0.3, \i-1) {\y};
% ~~~ roofs and lines ~~~~~~~~~
\draw[l1] (Z) -- (Y); % refactored coordinates, see above
\draw[l2] (X) -- (W);
\draw[r1] (ZZ) -- node[dev] {L3} (Z) -- (15,4.2);
\draw[r2] (0,.1) -- node[dev] {DRAM} (X);
% ~~~ data points and labels ~~~~~~~~~
\node[dp] (A) at (9.8,2.7) {};
\node[dp] (B) at (7.5,3.3) {};
\node[dp] (C) at (6.5,2) {};
\node[dp] (D) at (6.2,0.3) {};
\node[lbl] (AL) at ([shft]A) {LOG}; \draw (AL.60) -- (A);
\node[lbl] (BL) at ([shft]B) {KME}; \draw (BL.60) -- (B);
\node[lbl] (CL) at ([shft]C) {LIN}; \draw (CL.60) -- (C);
\node[lbl] (DL) at ([shftu]D) {DTR}; \draw (DL.300) -- (D);
% ~~~ peak note ~~~
\node[anchor=west] at (10.3,3.9) {Peak compute performance};
% ~~~ axes ~~~~~~~~~~~
\node at (7.5,-1) {Arithmetic Intensity (OP/B)};
\node[rotate=90] at (-1.3,2.1) {Performance (GOPS)};
\end{tikzpicture}
\end{document}