Tikz multi-bar plot custom bar position












2














I have a multi-bar plot that contains single and multi bars:



enter image description here



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}









share|improve this question






















  • 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
















2














I have a multi-bar plot that contains single and multi bars:



enter image description here



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}









share|improve this question






















  • 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














2












2








2







I have a multi-bar plot that contains single and multi bars:



enter image description here



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}









share|improve this question













I have a multi-bar plot that contains single and multi bars:



enter image description here



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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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) 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
















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















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
});


}
});














draft saved

draft discarded


















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
















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Can I use Tabulator js library in my java Spring + Thymeleaf project?