![pgfplots 跳转到中间标记,两端](https://linux22.com/image/264996/pgfplots%20%E8%B7%B3%E8%BD%AC%E5%88%B0%E4%B8%AD%E9%97%B4%E6%A0%87%E8%AE%B0%EF%BC%8C%E4%B8%A4%E7%AB%AF.png)
我想在 tikz-pgfplots 中绘制此图。但我不确定如何获得具有两端的跳跃中点标记。有什么想法吗?此外,由于我收到错误,这里的坐标是否以正确的格式正确分配?
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{pgfplots.units}
\usepgfplotslibrary{units}
\begin{document}
\begin{figure}[!ht]
\centering\makebox[\textwidth]
{
\begin{tikzpicture}
\begin{axis}[
width=15cm,
change y base,
y unit=microns,
ytick scale label code/.code={},
ytick={1,...,12},
scaled y ticks=base 10:-6,
xtick={1,...,12},
ylabel=Particle type,
xlabel=Particle diameter $\mu$ m,
yticklabel={\pgfmathprintnumber{\tick}{}},
symbolic y coords= {{Human Hair} ,
{Skin Flakes} ,
{Dus in air} ,
{Common Pollens} ,
{Mite Allergens} ,
{Common Spores} ,
{Bacteria} ,
{Cat Dander} ,
{Tobacco Smoke} ,
{Metal and} ,
{Cell Debris} ,
{Viruses}},
grid=major,
]
\addplot+[jump mark mid,ybar,error bars/.cd,y dir=both,y explicit]
coordinates
{
( {Human Hair} , 25 )+-( 100 , 150 )
( {Skin Flakes} , 30 )+-( 20 , 40 )
( {Dust in air} , 10 )+-( 10 , 100 )
( {Common Pollens} , 20 )+-( 15 , 25 )
( {Mite Allergens} , 15 )+-( 10 , 20 )
( {Common Spores} , 10 )+-( 10 , 15 )
( {Bacteria} , 1 )+-( 0.1 , 2 )
( {Cat Dander} , 1 )+-( 0.1 , 0.5 )
( {Tobacco Smoke} , 0.001 )+-( 0.001 , 0.005 )
( {Metal and} , 0.001 )+-( 0.001 , 0.001 )
( {Cell Debris} , 0.1 )+-( 0.1 , 1000 )
( {Viruses}, 0.1 )+-( 0.01 , 0.5 )
};
\end{axis}
\end{tikzpicture}}
\smallskip
\caption{Particle diameter ranges $\mu$m}
\label{fig:part_diam}
\end{figure}
\end{document}
答案1
我会(滥用)使用错误标记功能(因为看起来您也打算这么做),并以表格的形式提供数据,而不是使用关键字coordinates
:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots, pgfplotstable}
\begin{document}
\pgfplotstableread[col sep=comma]{
Label, Start, Range
Human Hair, 25,100
Skin Flakes, 30,20
Dust in air, 10,10
Common Pollens, 20,15
Mite Allergens, 15,10
Common Spores, 10,10
Bacteria, 1,1
Cat Dander, 1,1
Tobacco Smoke, 0.001,0.001
Metal and, 0.001,0.001
Cell Debris, 0.1,0.1
Viruses, 0.1,0.1
}\datatable
\pgfplotsset{compat=1.7}
\begin{tikzpicture}
\begin{axis}[
xmode=log,
ylabel=Particle type,
xlabel=Particle diameter $\mu$m,
ytick=data,
yticklabels from table={\datatable}{Label},
]
\addplot [
very thick,
only marks,
mark=|,
error bars/.cd,
x dir=plus,
x explicit,
error bar style={very thick},
error mark=|,
error mark options={draw, very thick}
]
table [col sep=comma, y expr=\coordindex, x index=1, x error index=2]
{\datatable};
\end{axis}
\end{tikzpicture}
\end{document}