我考虑过多加一个勾,但问题是这条线不适用于所有条形图,只适用于“重量”类别。是否可以在轴上画一条线,在重量之后结束?
这是MWE:
\documentclass[12pt,twoside]{report}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotstableread[row sep=\\,col sep=&]{
simname & default & rmat & cshell \\
Weight & 29.1 & 69.2 & 60 \\
F1L & 56.0 & 159.9 & 70 \\
F1U & 84.9 & 241.1 & 60 \\
F2L & 56.0 & 159.9 & 80 \\
F2U & 84.9 & 241.1 & 90 \\
F3L & 41.5 & 113.5 & 40 \\
F3U & 63.2 & 171.5 & 60 \\
F4U & 77.4 & 220.1 & 50 \\
F5U & 77.4 & 220.1 & 80 \\
F6U & 57.6 & 156.5 & 120 \\
}\dispdata
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[
width = \textwidth,
height = 10cm,
major x tick style = transparent,
ybar=0.05pt,
bar width=10pt,
ymajorgrids = true,
ylabel={Displacement~[\%~$L/200$]},
symbolic x coords={Weight, F1L, F1U, F2L, F2U, F3L, F3U, F4U, F5U, F6U},
xtick = data,
scaled y ticks = false,
ymin=0,ymax=260,
ytick style={draw=none},
legend cell align=left,
legend style={
at={(1,1.05)},
anchor=south east,
column sep=1ex
},
%extra y ticks = 100,
%extra y tick labels={},
%extra y tick style={grid=major,major grid style={very thick,draw=red}}
]
\addplot table[x=simname,y=default] {\dispdata};
\addplot table[x=simname,y=rmat] {\dispdata};
\addplot table[x=simname,y=cshell] {\dispdata};
\legend{Default, Removed Material, Complex Shell}
\end{axis}
\end{tikzpicture}
\caption{Comparison of Displacement Results from all Load Cases in the Different Simulation Configurations}
\label{fig:ch4-dispcompare}
\end{figure}
\end{document}
目前有这个:
我正在寻找这个:
答案1
您可以使用另一个\addplot
来绘制一条线。由于 x 坐标是符号,因此normalized
可以使用坐标。相应的线如下所示:
\addplot[red,sharp plot,update limits=false,] coordinates { ([normalized]-1,100) ([normalized]0.5,100) };
[normalized]0
对应于第一个 x 坐标 ( Weight
) 并[normalized]1
对应于第二个 x 坐标 ( F1L
)。[normalized]0.5
标记第一和第二之间的中点。[normalized]-1
用于获取xmin
。
输出:
梅威瑟:
\documentclass[12pt,twoside]{report}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotstableread[row sep=\\,col sep=&]{
simname & default & rmat & cshell \\
Weight & 29.1 & 69.2 & 60 \\
F1L & 56.0 & 159.9 & 70 \\
F1U & 84.9 & 241.1 & 60 \\
F2L & 56.0 & 159.9 & 80 \\
F2U & 84.9 & 241.1 & 90 \\
F3L & 41.5 & 113.5 & 40 \\
F3U & 63.2 & 171.5 & 60 \\
F4U & 77.4 & 220.1 & 50 \\
F5U & 77.4 & 220.1 & 80 \\
F6U & 57.6 & 156.5 & 120 \\
}\dispdata
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[
width = \textwidth,
height = 10cm,
major x tick style = transparent,
ybar=0.05pt,
bar width=10pt,
ymajorgrids = true,
ylabel={Displacement~[\%~$L/200$]},
symbolic x coords={Weight, F1L, F1U, F2L, F2U, F3L, F3U, F4U, F5U, F6U},
xtick = data,
scaled y ticks = false,
ymin=0,ymax=260,
ytick style={draw=none},
legend cell align=left,
legend style={
at={(1,1.05)},
anchor=south east,
column sep=1ex
},]
\addplot table[x=simname,y=default] {\dispdata};
\addplot table[x=simname,y=rmat] {\dispdata};
\addplot table[x=simname,y=cshell] {\dispdata};
\addplot[red,sharp plot,update limits=false,] coordinates { ([normalized]-1,100) ([normalized]0.5,100) };
\legend{Default, Removed Material, Complex Shell}
\end{axis}
\end{tikzpicture}
\caption{Comparison of Displacement Results from all Load Cases in the Different Simulation Configurations}
\label{fig:ch4-dispcompare}
\end{figure}
\end{document}