创建频率分配图

创建频率分配图

我需要在 TeX 中重现频率分配图。我更喜欢 TikZ,但对 PSTricks 持开放态度。我可以使用创建一个简单的条形分配图,\node但不确定如何创建分层块,例如下图示例中的深蓝色公共安全/宽带/保护带/LMR 块。

源图像

我当前的代码非常非常错误。块的大小是固定的,块的长度需要与分配的频率相对应;块之间也不接触。我们可以编写一个宏来根据某个输入长度绘制块吗?

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{figure}[!h]
\centering
\begin{tikzpicture}[node distance = 4cm, auto]

\tikzstyle{boxT}=[rectangle, draw=black!50, fill=teal, minimum width=5em, minimum height=3em, level distance=10cm,align=center, anchor=north, text=black, text width = 2.75cm]

\tikzstyle{boxB}=[rectangle, draw=black!50, fill=blue, minimum width=5em, minimum height=3em, level distance=10cm,align=center, anchor=north, text=white, text width = 2.75cm]

\node [boxT] (a) {Commercial};
\node [boxT, right of=a] (b) {Commercial};
\node [boxT, right of=b] (c) {D Block};
\node [boxB, right of=c] (d) {Broadband};
\node [boxB, right of=d] (e) {Guardband};
\node [boxB, above of=e] (f) {Public Safety};   

\end{tikzpicture}
\end{figure}
\end{document}

答案1

这里有一些初始代码,您可以将其用作起点(我没有放置所有标签);想法是使用一些预定义的样式和两个链:

\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{tikz}
\usetikzlibrary{arrows,chains,positioning,patterns,calc}

\tikzset{
boxT/.style={
  draw=none,
  rectangle,
  fill=teal!70,
  align=center,
  anchor=north,text width = 2.75cm,
  text height=5ex,
  text depth=2.5ex,
},
boxB/.style={boxT,text width=0.5cm,pin={[yshift=-6pt]below:Commercial}},
boxC/.style={boxT,text width=0.5cm,pin={[yshift=-6pt]below:Guardband}},
boxD/.style={boxT,fill=orange!90!black,text width=4.5cm,},
pinA/.style={
  pin={[yshift=10pt]below:%
    \tikz\node[inner sep=3pt,fill=orange!90!black,rounded corners] {Guardband};}},
boxE/.style={boxT,text width=#1},
boxF/.style={boxT,fill=orange!90!black,text width=#1},
boxG/.style={boxT,pattern=north east lines,text width=#1},
}

\newcommand\thtext[4]{%
  \node [boxD,on chain] (#1) {};
  \draw[white,line width=1pt] (#1.west) -- coordinate[pos=0.43] (aux1) coordinate[pos=0.57] (aux2) (#1.east);
  \draw[white,line width=1pt] (aux1) -- (aux1|-#1.south);
  \draw[white,line width=1pt] (aux2) -- (aux2|-#1.south);
  \node[label=below:{#2}] at (#1.north) {};
  \node[label={[xshift=-1.45cm]above:{#3}},anchor=west] at (#1.south) {};
  \node[label={[xshift=1.45cm]above:{#4}},anchor=east] at (#1.south) {};
}

\begin{document}

\begin{tikzpicture}[
  scale=0.7,
  transform shape,
  start chain,
  node distance=2pt,
  every pin edge/.style={*-,shorten <=-10pt}
]

\node[boxT,on chain] (a) {Commercial};
\node[boxB,on chain] (b) {};
\node[boxT,on chain] (c) {D Block};
\node[boxC,on chain] (d) {};
\thtext{e}{Public safety}{Broadband}{LMR}
\node[boxB,on chain] (f) {};   
\node[boxT,on chain] (g) {Commercial};
\node[boxC,on chain] (h) {};
\node[boxT,on chain] (i) {D Block};
\thtext{j}{Public safety}{Broadband}{LMR}
\node[boxB,on chain] (k) {};

\node[pinA] at (e.south) {};
\node[pinA] at (j.south) {};

\begin{scope}[start chain=1,yshift=4cm,node distance=0pt,outer sep=0pt]
\node[boxE=1cm,on chain=1,anchor=east] (a1) {};
\node[boxF=25pt,on chain=1] (b1) {};
\node[boxE=3cm,on chain=1] (c1) {};
\node[boxF=20pt,on chain=1] (d1) {};
\node[boxE=3cm,on chain=1] (e1) {};
\node[boxG=5pt,on chain=1] (f1) {};
\node[boxE=20pt,on chain=1] (g1) {};
\node[boxF=20pt,on chain=1] (h1) {};
\node[boxE=2pt,on chain=1] (i1) {};
\node[boxG=25pt,on chain=1] (j1) {};
\node[boxE=20pt,on chain=1] (k1) {};
\node[boxF=15pt,on chain=1] (l1) {};
\node[boxE=45pt,on chain=1] (m1) {};
\node[boxF=15pt,on chain=1] (n1) {};
\node[boxE=4cm,on chain=1] (o1) {};
\node[boxF=15pt,on chain=1] (p1) {};
\node[boxE=2.5cm,on chain=1] (q1) {};
\end{scope}
\draw[dashed] (a.north west) -- ( $ (k1) + (0,-30pt) $ ) -- (k1.north);
\draw[dashed] (k.north east) -- ( $ (l1) + (0,-30pt) $ ) -- (l1.north);
\end{tikzpicture}

\end{document}

在此处输入图片描述

该命令\thtext有四个参数:

\thtext{<name>}{<Upper text>}{<Lower left text>}{<Lower right text>}

其中<name>是节点的名称,其他参数是不言自明的;例如(使用上面定义的样式),

\thtext{kk}{Upper}{Lower L}{Lower R}

将生成一个名为 的节点kk,其布局如下:

在此处输入图片描述

相关内容