
첫 번째와 마지막 x축 레이블의 중심점뿐만 아니라 그래프의 전체 너비에 걸쳐 "Unseamed" 및 "Requirement" 선 그래프를 얻을 수 있는 방법이 있는지 궁금합니다. 이를 달성하기 위해 보이지 않는 x축 레이블을 만드는 방법이 있습니까?
\documentclass[a4paper,10pt]{report}
\usepackage{pgfplots}
\usetikzlibrary{patterns}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[width=11cm,
ybar,
enlargelimits=0.3,legend style={at={(0.98,0.98)},
cells={anchor=west}
},
legend entries={Straight,Unseamed,Zigzag,Requirement},
bar width=1cm,legend columns=2,
ylabel={Tensile strength{,} $N\,mm^{-1}$},
symbolic x coords={Plain,Single lap,Double lap},
xtick=data,
ytick={0,2,4,6,8,10,12,14},
x tick label style={rotate=45,anchor=east},
]
\addplot [draw=black,pattern=crosshatch dots,error bars/.cd,y dir=both,y explicit,error bar style={line width=1pt}]
coordinates
{
(Plain,7)+-(0.41,0.41)
(Single lap,11)+-(0.27,0.27)
(Double lap,12)+-(0.47,0.47)
};
\addplot[black,sharp plot]
coordinates {(Plain,10.857) (Double lap,10.857)}
;
\addplot [draw=black,error bars/.cd,y dir=both,y explicit,error bar style={line width=1pt}]
coordinates
{
(Plain,4)+-(0.31,0.31)
(Single lap,5)+-(0.27,0.27)
(Double lap,6)+-(0.38,0.38)
};
\addplot[black,sharp plot,dashed]
coordinates {(Plain,3.430) (Double lap,3.430)}
;
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
답변1
이를 달성하는 다소 우회적인 방법은 다음과 같습니다. 먼저 및 \coordinate
에 s를 추가 하고 하단 모서리에 좌표계를 추가 한 다음 이 좌표를 참조로 사용하여 선을 그립니다. 범례 항목은 으로 추가됩니다 .(Plain,3.43)
(Plain, 10.857)
rel axis cs
\addlegendimage
단위는 일반적으로 이탤릭체로 작성하면 안 되므로 변경하는 것이 좋습니다. 을 할 수도 있지만 $\mathrm{N}\,\mathrm{mm}^{-1}$
단위를 처리하는 더 좋은 방법 siunitx
은 \si{\newton\per\square\milli\metre}
. 또한 아래 코드(매뉴얼에서 가져온 ) 와 같이 기능을 결합할 수 있는 의 units
라이브러리에 대해 언급할 수 있습니다.pgfplots
siunitx
pgfplots
\documentclass[border=2mm,tikz]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{units}
\pgfplotsset{unit code/.code 2 args={\si{#1#2}}}
\usetikzlibrary{patterns}
\usepackage{siunitx}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=11cm,
ybar,
y unit=\newton\per\square\milli\metre,
enlargelimits=0.3,
legend style={
at={(0.98,0.98)},
cells={anchor=west},
column 3/.style={width=2cm}
},
legend entries={Straight,Unseamed,Zigzag,Requirement},
bar width=1cm,legend columns=2,
ylabel={Tensile strength},
symbolic x coords={Plain,Single lap,Double lap},
xtick=data,
ytick={0,2,4,6,8,10,12,14},
x tick label style={rotate=45,anchor=east},
]
\addplot [draw=black,pattern=crosshatch dots,error bars/.cd,y dir=both,y explicit,error bar style={line width=1pt}]
coordinates
{
(Plain,7)+-(0.41,0.41)
(Single lap,11)+-(0.27,0.27)
(Double lap,12)+-(0.47,0.47)
};
\addlegendimage{line legend,black,sharp plot}
\addplot [draw=black,error bars/.cd,y dir=both,y explicit,error bar style={line width=1pt}]
coordinates
{
(Plain,4)+-(0.31,0.31)
(Single lap,5)+-(0.27,0.27)
(Double lap,6)+-(0.38,0.38)
};
\addlegendimage{line legend,black,sharp plot,dashed}
\coordinate (A) at (axis cs:Plain,3.430);
\coordinate (B) at (axis cs:Plain,10.857);
\coordinate (O1) at (rel axis cs:0,0);
\coordinate (O2) at (rel axis cs:1,0);
\draw [black,sharp plot,dashed] (A -| O1) -- (A -| O2);
\draw [black,sharp plot] (B -| O1) -- (B -| O2);
\end{axis}
\end{tikzpicture}
\end{document}