答案1
我认为,一种可能性是定义pics
控制图表中的条目。在下面的代码中,我只处理由彩色条带和一些文本组成的条目,这些文本位于条带上方或下方;文本相对于条带的对齐方式也产生了两张图片,分别表示“上方文本”和“下方文本”。
评论。在pic
命名的below-left
(或-right
) 中,最后一个参数控制文本的长度,以防文本长度超过彩色条带。如果不是,则应将该参数设置为 0。也许图表中的above-left
(或) 可能需要类似的东西。-right
代码
\documentclass[11pt, margin=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{math}
\begin{document}
\tikzmath{
real \w;
\w = .2;
}
\tikzset{pics/.cd,
above-left/.style args={color=#1, length=#2, text=#3, label=#4}{
code={
\tikzmath{
real \tw;
\tw = #2 -.2;
}
\path[shade, left color=white, right color=#1]
(0, 0) rectangle ++(#2/5, \w);
\fill[#1] (#2/5, 0) rectangle ++(#2*3/5, \w);
\path[shade, left color=#1, right color=white]
(#2*4/5, 0) rectangle ++(#2/5, \w);
\path (0, \w +.1)
node[above right, minimum width=#2,
text width=\tw cm, align=left,
inner xsep=.1cm, inner ysep=0,
label={[minimum width=#2, align=left,
text width=\tw cm]90:{\tiny\mbox{#4}}
}, label distance=3pt]
{\tiny #3};
}
},
above-right/.style args={color=#1, length=#2, text=#3, label=#4}{
code={
\tikzmath{
real \tw;
\tw = #2 -.2;
}
\path[shade, left color=white, right color=#1]
(0, 0) rectangle ++(#2/5, \w);
\fill[#1] (#2/5, 0) rectangle ++(#2*3/5, \w);
\path[shade, left color=#1, right color=white]
(#2*4/5, 0) rectangle ++(#2/5, \w);
\path (#2, \w +.1)
node[above left, minimum width=#2,
text width=\tw cm, align=right,
inner xsep=.1cm, inner ysep=0,
label={[minimum width=#2, align=right,
text width=\tw cm]90:{\tiny\mbox{#4}}
}, label distance=3pt]
{\tiny #3};
}
},
below-left/.style args={color=#1, length=#2, text=#3, delta=#4}{
code={
\tikzmath{
real \tw;
\tw = #2 -.2 +#4;
}
\path[shade, left color=white, right color=#1]
(0, 0) rectangle ++(#2/5, \w);
\fill[#1] (#2/5, 0) rectangle ++(#2*3/5, \w);
\path[shade, left color=#1, right color=white]
(#2*4/5, 0) rectangle ++(#2/5, \w);
\path (0, -.1)
node[below right, minimum width=#2,
text width=\tw cm, align=left,
inner xsep=.1cm, inner ysep=0]
{\tiny #3};
}
},
below-right/.style args={color=#1, length=#2, text=#3, delta=#4}{
code={
\tikzmath{
real \tw;
\tw = #2 -.2 +#4;
}
\path[shade, left color=white, right color=#1]
(0, 0) rectangle ++(#2/5, \w);
\fill[#1] (#2/5, 0) rectangle ++(#2*3/5, \w);
\path[shade, left color=#1, right color=white]
(#2*4/5, 0) rectangle ++(#2/5, \w);
\path (#2, -.1)
node[below left, minimum width=#2,
text width=\tw cm, align=right,
inner xsep=.1cm, inner ysep=0]
{\tiny #3};
}
}
}
\begin{tikzpicture}
\foreach \t [count=\i from 0] in
{10 nm, 100 nm, 1\mu m, 10\mu m, 100\mu m, 1 mm, 10 mm}{%
\draw[gray, very thin] (1.5*\i, .2)
node[above, minimum height=4ex, inner ysep=1ex, scale=.8, text=black] {$\t$}
-- ++(0, -10.4);
}
\draw[ultra thick] (-.2, 0) -- (9.2, 0);
%% the pics
\path (5, -2) pic {below-left={color=red!80!black, length=1.5,
text={Unicellular \\[-5pt] marine algae},
delta=2}};
\path (5, -4) pic {below-right={color=red!80!black, length=1,
text={Human \\[-5pt] macrophage},
delta=2}};
\path (.1, -7) pic {above-right={color=black!70, length=3,
text={Py-GCMS$^\ast$ \\[-5pt]
(\$\,200,000-300,000)},
label={$<1\mu m$}}};
\path (2, -9) pic {above-left={color=black!70, length=7,
text={Micro-Raman spectroscopy (>50,000 \$) \\[-5pt]
(Black or dark colored particles cannot be identified)},
label={$>1\mu m$}}};
\end{tikzpicture}
\end{document}
答案2
感谢 Daniel,我找到了答案!我添加了对数刻度和文本块的变体。
\documentclass[11pt, margin=1cm]{article}
\usepackage{tikz}
\usetikzlibrary{math}
\usepackage{pgfplots}
\usepackage{siunitx}
\begin{document}
\tikzmath{
real \w;
\w = .2;
}
\tikzset{pics/.cd,
above-left/.style args={color=#1, length=#2, text=#3, label=#4}{
code={
\tikzmath{
real \tw;
\tw = #2 -.2;
}
\path[shade, left color=white, right color=#1]
(0, 0) rectangle ++(#2/5, \w);
\fill[#1] (#2/5, 0) rectangle ++(#2*3/5, \w);
\path[shade, left color=#1, right color=white]
(#2*4/5, 0) rectangle ++(#2/5, \w);
\path (0, \w +.1)
node[above right, minimum width=#2,
text width=\tw cm, align=left,
inner xsep=.1cm, inner ysep=0,
label={[minimum width=#2, align=left,
text width=\tw cm]90:{\tiny\mbox{#4}}
}, label distance=3pt]
{\tiny #3};
}
},
above-right/.style args={color=#1, length=#2, text=#3, label=#4}{
code={
\tikzmath{
real \tw;
\tw = #2 -.2;
}
\path[shade, left color=white, right color=#1]
(0, 0) rectangle ++(#2/5, \w);
\fill[#1] (#2/5, 0) rectangle ++(#2*3/5, \w);
\path[shade, left color=#1, right color=white]
(#2*4/5, 0) rectangle ++(#2/5, \w);
\path (#2, \w +.1)
node[above left, minimum width=#2,
text width=\tw cm, align=right,
inner xsep=.1cm, inner ysep=0,
label={[minimum width=#2, align=right,
text width=\tw cm]90:{\tiny\mbox{#4}}
}, label distance=3pt]
{\tiny #3};
}
},
inside-bar/.style args={color=#1, length=#2, text=#3, delta=#4}{
code={
\tikzmath{
real \tw;
\tw = #2 -.2 +#4;
}
\path[shade, left color=white, right color=#1]
(0, 0) rectangle ++(#2/7, 2.6*\w);
\fill[#1] (#2/7, 0) rectangle ++(#2*5/7, 2.6*\w);
\path[shade, left color=#1, right color=white]
(#2*4/5, 0) rectangle ++(#2/7, 2.6*\w);
\path (#2/2, 1.3*\w)
node[minimum width=#2,white,
text width=\tw cm, align=center,
inner xsep=.1cm, inner ysep=0]
{\footnotesize #3};
}
},
below-left/.style args={color=#1, length=#2, text=#3, delta=#4}{
code={
\tikzmath{
real \tw;
\tw = #2 -.2 +#4;
}
\path[shade, left color=white, right color=#1]
(0, 0) rectangle ++(#2/5, \w);
\fill[#1] (#2/5, 0) rectangle ++(#2*3/5, \w);
\path[shade, left color=#1, right color=white]
(#2*4/5, 0) rectangle ++(#2/5, \w);
\path (0, -.1)
node[below right, minimum width=#2,
text width=\tw cm, align=left,
inner xsep=.1cm, inner ysep=0]
{\tiny #3};
}
},
below-right/.style args={color=#1, length=#2, text=#3, delta=#4}{
code={
\tikzmath{
real \tw;
\tw = #2 -.2 +#4;
}
\path[shade, left color=white, right color=#1]
(0, 0) rectangle ++(#2/5, \w);
\fill[#1] (#2/5, 0) rectangle ++(#2*3/5, \w);
\path[shade, left color=#1, right color=white]
(#2*4/5, 0) rectangle ++(#2/5, \w);
\path (#2, -.1)
node[below left, minimum width=#2,
text width=\tw cm, align=right,
inner xsep=.1cm, inner ysep=0]
{\tiny #3};
}
}
}
\begin{tikzpicture}
\begin{axis}%
[
xmode=log,
log ticks with fixed point,
grid=both,
% axis line style={thick},
%xtick distance = 0.5,
ytick distance = 10,
%minor x tick num=0,
%minor y tick num=0,
x=0.87cm, y=1cm,
xmin=0.01, xmax=10000,
%minor x tick num={1},
tick label style={font=\tiny},
ymin=0, ymax=10,
xticklabels=\empty,
yticklabels=\empty,
]
\end{axis}
\foreach \t [count=\i from 0] in
{\SI{10}{\mm}, \SI{100}{\nm}, \SI{1}{\micro\m}, \SI{10}{\micro\m}, \SI{100}{\micro\m}, \SI{1}{\mm}, \SI{10}{\mm}}{%
\draw[black] (2*\i, 10) node[above, minimum height=4ex, inner ysep=1ex, scale=.8, text=black] {$\t$} --++ (0,-10);
\draw[gray, very thin, dashed] (2*\i, -.2)
node[below, minimum height=4ex, inner ysep=1ex, scale=.8, text=black] {$\t$};
}
%\draw[ultra thick] (-.2, 0) --++ (10.4, 0);
%\draw[ultra thick] (-.2, -8) --++ (10.4, 0);
% onderscheid plastics
\path (0, 10.7) pic {inside-bar={color=orange!80!black, length=4, text={Nanoplastics}, delta=2}};
\path (4, 10.7) pic {inside-bar={color=orange!80!black, length=8, text={Microplastics}, delta=2}};
%% De balkjes
\path (10, 8.5) pic {above-left={color=black!70, length=2, text={Naked-eye}, label={$> \SI{1}{\mm}$}}};
\path (8, 7) pic {above-left={color=black!70, length=4, text={Optical microscope\\[-5pt] (\$ \num{700}$-$\num{3000})}, label={$> \SI{1}{\mm}$}}};
\path (0, 5) pic {above-left={color=black!70, length=4.2, text={Py-GCMS$^\ast$ \\[-5pt] (\$ \num{200000}$-$\num{300000})},
label={$< \SI{1}{\micro\m}$}}};
\path (6, 5) pic {above-left={color=black!70, length=6, text={FTIR \\[-5pt] (\$ \num{25000})},
label={$> \SI{10}{\micro\m}-\SI{20}{\micro\m}$}}};
\path (3.8, 3) pic {above-left={color=black!70, length=8.2, text={Micro-Raman spectroscopy ($ >\$\num{50000}$) \\[-5pt] (Black or dark colored particles cannot be identified)}, label={$>\SI{1}{\micro\m}$}}};
\path (4.6, 1) pic {above-left={color=black!70, length=7.4, text={Nile red staining + fluorescence micorsocopy\\[-5pt] ($ >\$\num{2000}-\num{50000}$) }, label={$>\SI{3}{\micro\m}$}}};
\end{tikzpicture}
\end{document}