Tikz multi-bar plot custom bar position
I have a multi-bar plot that contains single and multi bars:
I want to make the single bars A and D in the center; right now they are left aligned.
The following is the code:
begin{tikzpicture}
begin{axis}[
ybar, axis on top, height=8cm, width=8cm, bar width=0.6cm, ymajorgrids, tick align=inside,
major grid style={draw=white}, enlarge y limits={value=0.1,upper}, ymin=0, ymax=40,
axis x line*=bottom, axis y line*=left, y axis line style={opacity=0}, tickwidth=0pt,
enlarge x limits=true,
ylabel={Percentage (%)},
ylabel style={align=center},
symbolic x coords={
A,B,C,D
},
xtick=data,
nodes near coords={
pgfmathprintnumber[precision=1]{pgfplotspointmeta}
},
x tick label style={font=small,text width=2cm,align=center}
]
addplot [draw=none, fill=blue!60] coordinates {
(A, 25.6)
(B, 10.3)
(C, 35.7)
(D, 22.4) };
addplot [draw=none,fill=red!30,opacity=1] coordinates {
(B, 19.6)
(C, 26.1) };
end{axis}
end{tikzpicture}
tikz-pgf pgfplots bar-chart
add a comment |
I have a multi-bar plot that contains single and multi bars:
I want to make the single bars A and D in the center; right now they are left aligned.
The following is the code:
begin{tikzpicture}
begin{axis}[
ybar, axis on top, height=8cm, width=8cm, bar width=0.6cm, ymajorgrids, tick align=inside,
major grid style={draw=white}, enlarge y limits={value=0.1,upper}, ymin=0, ymax=40,
axis x line*=bottom, axis y line*=left, y axis line style={opacity=0}, tickwidth=0pt,
enlarge x limits=true,
ylabel={Percentage (%)},
ylabel style={align=center},
symbolic x coords={
A,B,C,D
},
xtick=data,
nodes near coords={
pgfmathprintnumber[precision=1]{pgfplotspointmeta}
},
x tick label style={font=small,text width=2cm,align=center}
]
addplot [draw=none, fill=blue!60] coordinates {
(A, 25.6)
(B, 10.3)
(C, 35.7)
(D, 22.4) };
addplot [draw=none,fill=red!30,opacity=1] coordinates {
(B, 19.6)
(C, 26.1) };
end{axis}
end{tikzpicture}
tikz-pgf pgfplots bar-chart
Welcome to TeX.SX. Those are actually center aligned. Since you don't have data in the second set (red) forA
andD
, those bars are not plotted but the space for that is allotted. That's why it looks left aligned.
– nidhin
Dec 10 at 21:11
add a comment |
I have a multi-bar plot that contains single and multi bars:
I want to make the single bars A and D in the center; right now they are left aligned.
The following is the code:
begin{tikzpicture}
begin{axis}[
ybar, axis on top, height=8cm, width=8cm, bar width=0.6cm, ymajorgrids, tick align=inside,
major grid style={draw=white}, enlarge y limits={value=0.1,upper}, ymin=0, ymax=40,
axis x line*=bottom, axis y line*=left, y axis line style={opacity=0}, tickwidth=0pt,
enlarge x limits=true,
ylabel={Percentage (%)},
ylabel style={align=center},
symbolic x coords={
A,B,C,D
},
xtick=data,
nodes near coords={
pgfmathprintnumber[precision=1]{pgfplotspointmeta}
},
x tick label style={font=small,text width=2cm,align=center}
]
addplot [draw=none, fill=blue!60] coordinates {
(A, 25.6)
(B, 10.3)
(C, 35.7)
(D, 22.4) };
addplot [draw=none,fill=red!30,opacity=1] coordinates {
(B, 19.6)
(C, 26.1) };
end{axis}
end{tikzpicture}
tikz-pgf pgfplots bar-chart
I have a multi-bar plot that contains single and multi bars:
I want to make the single bars A and D in the center; right now they are left aligned.
The following is the code:
begin{tikzpicture}
begin{axis}[
ybar, axis on top, height=8cm, width=8cm, bar width=0.6cm, ymajorgrids, tick align=inside,
major grid style={draw=white}, enlarge y limits={value=0.1,upper}, ymin=0, ymax=40,
axis x line*=bottom, axis y line*=left, y axis line style={opacity=0}, tickwidth=0pt,
enlarge x limits=true,
ylabel={Percentage (%)},
ylabel style={align=center},
symbolic x coords={
A,B,C,D
},
xtick=data,
nodes near coords={
pgfmathprintnumber[precision=1]{pgfplotspointmeta}
},
x tick label style={font=small,text width=2cm,align=center}
]
addplot [draw=none, fill=blue!60] coordinates {
(A, 25.6)
(B, 10.3)
(C, 35.7)
(D, 22.4) };
addplot [draw=none,fill=red!30,opacity=1] coordinates {
(B, 19.6)
(C, 26.1) };
end{axis}
end{tikzpicture}
tikz-pgf pgfplots bar-chart
tikz-pgf pgfplots bar-chart
asked Dec 10 at 20:00
cagryInside
1112
1112
Welcome to TeX.SX. Those are actually center aligned. Since you don't have data in the second set (red) forA
andD
, those bars are not plotted but the space for that is allotted. That's why it looks left aligned.
– nidhin
Dec 10 at 21:11
add a comment |
Welcome to TeX.SX. Those are actually center aligned. Since you don't have data in the second set (red) forA
andD
, those bars are not plotted but the space for that is allotted. That's why it looks left aligned.
– nidhin
Dec 10 at 21:11
Welcome to TeX.SX. Those are actually center aligned. Since you don't have data in the second set (red) for
A
and D
, those bars are not plotted but the space for that is allotted. That's why it looks left aligned.– nidhin
Dec 10 at 21:11
Welcome to TeX.SX. Those are actually center aligned. Since you don't have data in the second set (red) for
A
and D
, those bars are not plotted but the space for that is allotted. That's why it looks left aligned.– nidhin
Dec 10 at 21:11
add a comment |
active
oldest
votes
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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%2f464199%2ftikz-multi-bar-plot-custom-bar-position%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f464199%2ftikz-multi-bar-plot-custom-bar-position%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
Welcome to TeX.SX. Those are actually center aligned. Since you don't have data in the second set (red) for
A
andD
, those bars are not plotted but the space for that is allotted. That's why it looks left aligned.– nidhin
Dec 10 at 21:11