我正在使用这个符号在我的工作中。我试图在这个代码中添加一个图例来注释图表。我发现这个代码Tikzpicture 中的图例所以我现在有以下代码:
\documentclass[tikz,border=5]{standalone}
\renewcommand\familydefault\sfdefault
\usetikzlibrary{fit,shapes.geometric}
\pgfdeclarelayer{signal}
\pgfsetlayers{signal,main}
\usepackage{pgfplots}
\usetikzlibrary{arrows,arrows.meta}
\tikzset{pics/.cd,
SBS/.style={code={
\begin{scope}[local bounding box=#1]
\fill [pic actions/.try] (-1,0) -- (-1/2,3) -- (1/2, 3) -- (1,0) -- cycle;
\fill [pic actions/.try] (-1/16,2) rectangle (1/16,4);
\fill [pic actions/.try] (0,4) circle [radius=1/4];
\foreach \i in {-1,1}
\fill [shift=(90:4), xscale=\i]
\foreach \r in {1,3/2,2}{
(-45:\r) arc (-45:45:\r) -- (45:\r-1/10)
arc(45:-45:\r-1/10) -- cycle
};
\end{scope}
}},
SU/.style={code={
\begin{scope}[local bounding box=#1]
\fill [even odd rule, pic actions/.try]
(-1,-5/2) -- (-1,-1/8) -- (1,-1/8) -- (1,-5/2)
arc (360:180:1 and 1/4) -- cycle
(-1,5/2) -- (-1,1/8) -- (1,1/8) -- (1,5/2)
arc (0:180:1 and 1/4) -- cycle
(-3/4, 9/4) -- (-3/4, 3/8) -- (3/4, 3/8) -- (3/4, 9/4)
arc (0:180:3/4 and 1/8)-- cycle
\foreach \i in {-1,0,1}{\foreach \j in {1,2,3}{
(-\i*1/2-3/16,-\j/2-3/4) rectangle ++(3/8, 3/8)}}
(-1/2,-3/4) rectangle (1/2, -1/4);
\end{scope}
}},
SIGNAL/.style={code={
\begin{scope}[local bounding box=#1]
\fill [pic actions/.try]
(0,-3) -- (-1,1/2) -- (1/8,1/4) -- (0,3) -- (1,-1/2) -- (-1/8,-1/4)
-- cycle;
\end{scope}
}}
}
\newenvironment{customlegend}[1][]{%
\begingroup
% inits/clears the lists (which might be populated from previous
% axes):
\csname pgfplots@init@cleared@structures\endcsname
\pgfplotsset{#1}%
}{%
% draws the legend:
\csname pgfplots@createlegend\endcsname
\endgroup
}%
% makes \addlegendimage available (typically only available within an
% axis environment):
\def\addlegendimage{\csname pgfplots@addlegendimage\endcsname}
%%--------------------------------
% definition to insert numbers
\pgfkeys{/pgfplots/number in legend/.style={%
/pgfplots/legend image code/.code={%
\node at (0.295,-0.0225){#1};
},%
},
}
\colorlet{sky blue}{blue!60!cyan!75!black}
\colorlet{dark blue}{blue!50!cyan}
\colorlet{chameleon}{olive!75!green}
\tikzset{signal/.style={draw=gray, line width=0.2em, dashed}}
\begin{document}
\begin{tikzpicture}[x=1em,y=1em]
\begin{scope}[local bounding box=b1]
\pic [fill=sky blue] {SBS=p1};
\pic [rotate=15, fill=sky blue] at (8,-4) {SU=q1};
\pic [rotate=45, fill=sky blue] at (4,-2) {SIGNAL=s1};
\node [line width=0.25em,draw=sky blue, shape=circle, fit={(p1) (q1) (s1)}] {};
\path (p1.north) node [below] {p1} (q1.north east) node [above] {q1};
\end{scope}
\begin{scope}[shift={(25,5)}, x=1em*7/8, y=1em*7/8, local bounding box=b2]
\pic [fill=chameleon] {SBS=p2};
\pic [fill=chameleon] at (-8,0) {SU=q2};
\pic [rotate=-75, fill=chameleon] at (-4,1) {SIGNAL=s2};
\node [line width=0.25em,draw=chameleon, inner sep=1em,
shape=circle, fit={(p2) (q2) (s2)}] {};
\path (p2.south) node [below] {p2} (q2.south) node [below] {q2};
\end{scope}
\begin{scope}[shift={(5,20)}, x=1em*5/8, y=1em*5/8, local bounding box=b3]
\pic [fill=violet] {SBS=p3};
\pic [fill=violet] at (8,0) {SU=q3};
\pic [rotate=-75, fill=violet] at (4,1) {SIGNAL=s3};
\node [line width=0.25em, draw=violet, inner sep=1em,
shape=circle, fit={(p3) (q3) (s3)}] {};
\path (p3.north) node [above] {p3} (q3.south) node [below] {q3};
\end{scope}
\begin{pgfonlayer}{signal}
\draw [signal]
(p1) -- (q3) -- (p2) -- (q1) -- (p3) -- (q2) -- (p1)
(p1) -- (q1) (p2) -- (q2) (p3) -- (q3);
\end{pgfonlayer}
\node [regular polygon, regular polygon sides=6, fit={(b1) (b2) (b3)},
draw=black, line width=0.25em, inner sep=-2em]
{};
\pic [fill=dark blue] at (-5, 10) {SBS};
\pic [fill=dark blue] at (25, 15) {SBS};
\pic [fill=dark blue] at (20, -8) {SU};
\begin{customlegend}[
legend entries={ % <= in the following there are the entries
Interference,
Strong Signal,
Weak Signal
},
scale=4,
% legend cell align={left},
legend style={at={(-4,0)}}] % <= to define position and font legend
% the following are the "images" and numbers in the legend
\addlegendimage{-triangle 45,red,line width=0.3mm}
\addlegendimage{-triangle 45,cyan,line width=0.3mm}
\addlegendimage{-triangle 45,cyan,dashed,line width=0.3mm}
\end{customlegend}
\end{tikzpicture}
\end{document}
我的问题是图例总是很小,我尝试添加,nodes={scale=2}
但增加了文字,但没有增加箭头。图例中还有一些表情符号,看起来真的很小。
如何使图例变大(包括文字、符号、节点和表情符号)?
有没有更好的方法来添加图例?假设我想将手机添加到图例中,我该怎么做?
我目前得到的结果如下:
答案1
我只能提供一种解决方法,因为我不太了解宏,pgfplots@init@cleared@structures
也\csname pgfplots@createlegend\endcsname
不太敢玩它们。所以我建议手工绘制图例。
\documentclass[tikz,border=5]{standalone}
\renewcommand\familydefault\sfdefault
\usetikzlibrary{fit,shapes.geometric}
\pgfdeclarelayer{signal}
\pgfdeclarelayer{legend back}
\pgfdeclarelayer{legend}
\pgfsetlayers{signal,main,legend back,legend}
\usetikzlibrary{arrows,arrows.meta}
\tikzset{pics/.cd,
SBS/.style={code={
\begin{scope}[local bounding box=#1]
\fill [pic actions/.try] (-1,0) -- (-1/2,3) -- (1/2, 3) -- (1,0) -- cycle;
\fill [pic actions/.try] (-1/16,2) rectangle (1/16,4);
\fill [pic actions/.try] (0,4) circle [radius=1/4];
\foreach \i in {-1,1}
\fill [shift=(90:4), xscale=\i]
\foreach \r in {1,3/2,2}{
(-45:\r) arc (-45:45:\r) -- (45:\r-1/10)
arc(45:-45:\r-1/10) -- cycle
};
\end{scope}
}},
SU/.style={code={
\begin{scope}[local bounding box=#1]
\fill [even odd rule, pic actions/.try]
(-1,-5/2) -- (-1,-1/8) -- (1,-1/8) -- (1,-5/2)
arc (360:180:1 and 1/4) -- cycle
(-1,5/2) -- (-1,1/8) -- (1,1/8) -- (1,5/2)
arc (0:180:1 and 1/4) -- cycle
(-3/4, 9/4) -- (-3/4, 3/8) -- (3/4, 3/8) -- (3/4, 9/4)
arc (0:180:3/4 and 1/8)-- cycle
\foreach \i in {-1,0,1}{\foreach \j in {1,2,3}{
(-\i*1/2-3/16,-\j/2-3/4) rectangle ++(3/8, 3/8)}}
(-1/2,-3/4) rectangle (1/2, -1/4);
\end{scope}
}},
SIGNAL/.style={code={
\begin{scope}[local bounding box=#1]
\fill [pic actions/.try]
(0,-3) -- (-1,1/2) -- (1/8,1/4) -- (0,3) -- (1,-1/2) -- (-1/8,-1/4)
-- cycle;
\end{scope}
}}
}
\colorlet{sky blue}{blue!60!cyan!75!black}
\colorlet{dark blue}{blue!50!cyan}
\colorlet{chameleon}{olive!75!green}
\tikzset{signal/.style={draw=gray, line width=0.2em, dashed}}
\begin{document}
\begin{tikzpicture}[x=1em,y=1em]
\begin{scope}[local bounding box=b1]
\pic [fill=sky blue] {SBS=p1};
\pic [rotate=15, fill=sky blue] at (8,-4) {SU=q1};
\pic [rotate=45, fill=sky blue] at (4,-2) {SIGNAL=s1};
\node [line width=0.25em,draw=sky blue, shape=circle, fit={(p1) (q1) (s1)}] {};
\path (p1.north) node [below] {p1} (q1.north east) node [above] {q1};
\end{scope}
\begin{scope}[shift={(25,5)}, x=1em*7/8, y=1em*7/8, local bounding box=b2]
\pic [fill=chameleon] {SBS=p2};
\pic [fill=chameleon] at (-8,0) {SU=q2};
\pic [rotate=-75, fill=chameleon] at (-4,1) {SIGNAL=s2};
\node [line width=0.25em,draw=chameleon, inner sep=1em,
shape=circle, fit={(p2) (q2) (s2)}] {};
\path (p2.south) node [below] {p2} (q2.south) node [below] {q2};
\end{scope}
\begin{scope}[shift={(5,20)}, x=1em*5/8, y=1em*5/8, local bounding box=b3]
\pic [fill=violet] {SBS=p3};
\pic [fill=violet] at (8,0) {SU=q3};
\pic [rotate=-75, fill=violet] at (4,1) {SIGNAL=s3};
\node [line width=0.25em, draw=violet, inner sep=1em,
shape=circle, fit={(p3) (q3) (s3)}] {};
\path (p3.north) node [above] {p3} (q3.south) node [below] {q3};
\end{scope}
\begin{pgfonlayer}{signal}
\draw [signal]
(p1) -- (q3) -- (p2) -- (q1) -- (p3) -- (q2) -- (p1)
(p1) -- (q1) (p2) -- (q2) (p3) -- (q3);
\end{pgfonlayer}
\node [regular polygon, regular polygon sides=6, fit={(b1) (b2) (b3)},
draw=black, line width=0.25em, inner sep=-2em]
{};
\pic [fill=dark blue] at (-5, 10) {SBS};
\pic [fill=dark blue] at (25, 15) {SBS};
\pic [fill=dark blue] at (20, -8) {SU};
\begin{scope}[local bounding box=legend,shift={(-8,0)},scale=3,transform shape]
\begin{pgfonlayer}{legend}
\pgfgettransformentries{\myscale}{\tmp}{\tmp}{\tmp}{\tmp}{\tmp}
\coordinate (aux) at (-0.1,0);
\draw[-triangle 45,red,line width=\myscale*0.3mm] (0,0) -- ++ (1.6,0)
node[right,black]{Interference};
\draw[-triangle 45,cyan,line width=\myscale*0.3mm] (0,-1) -- ++ (1.6,0)
node[right,black]{Strong Signal};
\draw[-triangle 45,cyan,dashed,line width=\myscale*0.3mm] (0,-2) -- ++ (1.6,0)
node[right,black]{Weak Signal};
\end{pgfonlayer}
\end{scope}
\begin{pgfonlayer}{legend back}
\node[fit=(legend) (aux),fill=white,thick,draw,inner sep=2pt]{};
\end{pgfonlayer}
\end{tikzpicture}
\end{document}
我要说的是,你正在加载和arrows
,arrows.meta
但只使用arrows
。尽管在这里这并不重要,但我建议使用arrows.meta
。