tikzpicture pgf bar plot - Add Horizontal line that starts in axis and ends after 1st group of bars
up vote
2
down vote
favorite
I thought about doing an extra tick but the problem is that the line isn't applicable to all bars, only the "Weight" category. Is it possible to have a line starting on the axis and ending after Weight?
Here's the 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}
Currently have this:
And I'm looking for this:
tikz-pgf pgfplots bar-chart
add a comment |
up vote
2
down vote
favorite
I thought about doing an extra tick but the problem is that the line isn't applicable to all bars, only the "Weight" category. Is it possible to have a line starting on the axis and ending after Weight?
Here's the 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}
Currently have this:
And I'm looking for this:
tikz-pgf pgfplots bar-chart
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I thought about doing an extra tick but the problem is that the line isn't applicable to all bars, only the "Weight" category. Is it possible to have a line starting on the axis and ending after Weight?
Here's the 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}
Currently have this:
And I'm looking for this:
tikz-pgf pgfplots bar-chart
I thought about doing an extra tick but the problem is that the line isn't applicable to all bars, only the "Weight" category. Is it possible to have a line starting on the axis and ending after Weight?
Here's the 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}
Currently have this:
And I'm looking for this:
tikz-pgf pgfplots bar-chart
tikz-pgf pgfplots bar-chart
asked Nov 18 at 12:57
Rafael de Gomes
544
544
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
You can use another addplot
to plot a line. Since the x-coordinates are symbolic, normalized
coordinates can be used. The corresponding line looks like this:
addplot[red,sharp plot,update limits=false,] coordinates { ([normalized]-1,100) ([normalized]0.5,100) };
[normalized]0
corresponds to first x coordinate (Weight
) and [normalized]1
corresponds to second x coordinate (F1L
). [normalized]0.5
marks the midpoint between first and second. [normalized]-1
was used to get the xmin
.
output:
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
},]
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}
That worked wonderfully! I tried using an addplot but instead added another bar to the graph unintentionally. Yours works perfectly, thank you very much!
– Rafael de Gomes
Nov 18 at 14:33
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
You can use another addplot
to plot a line. Since the x-coordinates are symbolic, normalized
coordinates can be used. The corresponding line looks like this:
addplot[red,sharp plot,update limits=false,] coordinates { ([normalized]-1,100) ([normalized]0.5,100) };
[normalized]0
corresponds to first x coordinate (Weight
) and [normalized]1
corresponds to second x coordinate (F1L
). [normalized]0.5
marks the midpoint between first and second. [normalized]-1
was used to get the xmin
.
output:
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
},]
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}
That worked wonderfully! I tried using an addplot but instead added another bar to the graph unintentionally. Yours works perfectly, thank you very much!
– Rafael de Gomes
Nov 18 at 14:33
add a comment |
up vote
2
down vote
accepted
You can use another addplot
to plot a line. Since the x-coordinates are symbolic, normalized
coordinates can be used. The corresponding line looks like this:
addplot[red,sharp plot,update limits=false,] coordinates { ([normalized]-1,100) ([normalized]0.5,100) };
[normalized]0
corresponds to first x coordinate (Weight
) and [normalized]1
corresponds to second x coordinate (F1L
). [normalized]0.5
marks the midpoint between first and second. [normalized]-1
was used to get the xmin
.
output:
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
},]
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}
That worked wonderfully! I tried using an addplot but instead added another bar to the graph unintentionally. Yours works perfectly, thank you very much!
– Rafael de Gomes
Nov 18 at 14:33
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
You can use another addplot
to plot a line. Since the x-coordinates are symbolic, normalized
coordinates can be used. The corresponding line looks like this:
addplot[red,sharp plot,update limits=false,] coordinates { ([normalized]-1,100) ([normalized]0.5,100) };
[normalized]0
corresponds to first x coordinate (Weight
) and [normalized]1
corresponds to second x coordinate (F1L
). [normalized]0.5
marks the midpoint between first and second. [normalized]-1
was used to get the xmin
.
output:
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
},]
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}
You can use another addplot
to plot a line. Since the x-coordinates are symbolic, normalized
coordinates can be used. The corresponding line looks like this:
addplot[red,sharp plot,update limits=false,] coordinates { ([normalized]-1,100) ([normalized]0.5,100) };
[normalized]0
corresponds to first x coordinate (Weight
) and [normalized]1
corresponds to second x coordinate (F1L
). [normalized]0.5
marks the midpoint between first and second. [normalized]-1
was used to get the xmin
.
output:
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
},]
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}
edited Nov 18 at 14:09
answered Nov 18 at 14:02
nidhin
1,700920
1,700920
That worked wonderfully! I tried using an addplot but instead added another bar to the graph unintentionally. Yours works perfectly, thank you very much!
– Rafael de Gomes
Nov 18 at 14:33
add a comment |
That worked wonderfully! I tried using an addplot but instead added another bar to the graph unintentionally. Yours works perfectly, thank you very much!
– Rafael de Gomes
Nov 18 at 14:33
That worked wonderfully! I tried using an addplot but instead added another bar to the graph unintentionally. Yours works perfectly, thank you very much!
– Rafael de Gomes
Nov 18 at 14:33
That worked wonderfully! I tried using an addplot but instead added another bar to the graph unintentionally. Yours works perfectly, thank you very much!
– Rafael de Gomes
Nov 18 at 14:33
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f460589%2ftikzpicture-pgf-bar-plot-add-horizontal-line-that-starts-in-axis-and-ends-afte%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown