How to generate a customised histogram with pgf plots?












3















I am trying to generate a histogram like the following:



enter image description here



While going through the examples pgf plots, I was able to generate a histogram similar to the following:



enter image description here



using the code from the example link shared above:



    documentclass{article}
usepackage{csvsimple}
usepackage{longtable}
usepackage{xcolor}
usepackage{booktabs}
usepackage{caption}
usepackage{pgfplots}



begin{document}
begin{tikzpicture}
begin{axis}[
x tick label style={
/pgf/number format/1000 sep=},
ylabel=Year,
enlargelimits=0.05,
legend style={at={(0.5,-0.1)},
anchor=north,legend columns=-1},
ybar interval=0.7,
]
addplot
coordinates {(2012,408184) (2011,408348)
(2010,414870) (2009,412156)};
addplot
coordinates {(2012,388950) (2011,393007)
(2010,398449) (2009,395972)};
legend{Men,Women}
end{axis}
end{tikzpicture}
end{document}


Is there a way with pgf plots, where I could generate custom looking histogram?










share|improve this question







New contributor




Amanda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • How about rounded corners: addplot[rounded corners=8pt,fill=blue!60!black] coordinates {(2012,408184) (2011,408348) (2010,414870) (2009,412156)}; addplot[rounded corners=3pt,fill=red!60!black] coordinates {(2012,388950) (2011,393007) (2010,398449) (2009,395972)};?

    – marmot
    1 hour ago











  • @marmot, good idea, however the legend is than screwy ... can you fix this?

    – Zarko
    1 hour ago













  • @marmot Could we also remove the y axis and have the corresponding values at the top of histogram?

    – Amanda
    57 mins ago











  • @Zarko Yes. It took me a while to realize that the OP uses ybar interval rather than ybar, where I was stuck... ;-)

    – marmot
    26 mins ago
















3















I am trying to generate a histogram like the following:



enter image description here



While going through the examples pgf plots, I was able to generate a histogram similar to the following:



enter image description here



using the code from the example link shared above:



    documentclass{article}
usepackage{csvsimple}
usepackage{longtable}
usepackage{xcolor}
usepackage{booktabs}
usepackage{caption}
usepackage{pgfplots}



begin{document}
begin{tikzpicture}
begin{axis}[
x tick label style={
/pgf/number format/1000 sep=},
ylabel=Year,
enlargelimits=0.05,
legend style={at={(0.5,-0.1)},
anchor=north,legend columns=-1},
ybar interval=0.7,
]
addplot
coordinates {(2012,408184) (2011,408348)
(2010,414870) (2009,412156)};
addplot
coordinates {(2012,388950) (2011,393007)
(2010,398449) (2009,395972)};
legend{Men,Women}
end{axis}
end{tikzpicture}
end{document}


Is there a way with pgf plots, where I could generate custom looking histogram?










share|improve this question







New contributor




Amanda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





















  • How about rounded corners: addplot[rounded corners=8pt,fill=blue!60!black] coordinates {(2012,408184) (2011,408348) (2010,414870) (2009,412156)}; addplot[rounded corners=3pt,fill=red!60!black] coordinates {(2012,388950) (2011,393007) (2010,398449) (2009,395972)};?

    – marmot
    1 hour ago











  • @marmot, good idea, however the legend is than screwy ... can you fix this?

    – Zarko
    1 hour ago













  • @marmot Could we also remove the y axis and have the corresponding values at the top of histogram?

    – Amanda
    57 mins ago











  • @Zarko Yes. It took me a while to realize that the OP uses ybar interval rather than ybar, where I was stuck... ;-)

    – marmot
    26 mins ago














3












3








3








I am trying to generate a histogram like the following:



enter image description here



While going through the examples pgf plots, I was able to generate a histogram similar to the following:



enter image description here



using the code from the example link shared above:



    documentclass{article}
usepackage{csvsimple}
usepackage{longtable}
usepackage{xcolor}
usepackage{booktabs}
usepackage{caption}
usepackage{pgfplots}



begin{document}
begin{tikzpicture}
begin{axis}[
x tick label style={
/pgf/number format/1000 sep=},
ylabel=Year,
enlargelimits=0.05,
legend style={at={(0.5,-0.1)},
anchor=north,legend columns=-1},
ybar interval=0.7,
]
addplot
coordinates {(2012,408184) (2011,408348)
(2010,414870) (2009,412156)};
addplot
coordinates {(2012,388950) (2011,393007)
(2010,398449) (2009,395972)};
legend{Men,Women}
end{axis}
end{tikzpicture}
end{document}


Is there a way with pgf plots, where I could generate custom looking histogram?










share|improve this question







New contributor




Amanda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












I am trying to generate a histogram like the following:



enter image description here



While going through the examples pgf plots, I was able to generate a histogram similar to the following:



enter image description here



using the code from the example link shared above:



    documentclass{article}
usepackage{csvsimple}
usepackage{longtable}
usepackage{xcolor}
usepackage{booktabs}
usepackage{caption}
usepackage{pgfplots}



begin{document}
begin{tikzpicture}
begin{axis}[
x tick label style={
/pgf/number format/1000 sep=},
ylabel=Year,
enlargelimits=0.05,
legend style={at={(0.5,-0.1)},
anchor=north,legend columns=-1},
ybar interval=0.7,
]
addplot
coordinates {(2012,408184) (2011,408348)
(2010,414870) (2009,412156)};
addplot
coordinates {(2012,388950) (2011,393007)
(2010,398449) (2009,395972)};
legend{Men,Women}
end{axis}
end{tikzpicture}
end{document}


Is there a way with pgf plots, where I could generate custom looking histogram?







tikz-pgf pgfplots histogram






share|improve this question







New contributor




Amanda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Amanda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Amanda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 1 hour ago









AmandaAmanda

474




474




New contributor




Amanda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Amanda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Amanda is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













  • How about rounded corners: addplot[rounded corners=8pt,fill=blue!60!black] coordinates {(2012,408184) (2011,408348) (2010,414870) (2009,412156)}; addplot[rounded corners=3pt,fill=red!60!black] coordinates {(2012,388950) (2011,393007) (2010,398449) (2009,395972)};?

    – marmot
    1 hour ago











  • @marmot, good idea, however the legend is than screwy ... can you fix this?

    – Zarko
    1 hour ago













  • @marmot Could we also remove the y axis and have the corresponding values at the top of histogram?

    – Amanda
    57 mins ago











  • @Zarko Yes. It took me a while to realize that the OP uses ybar interval rather than ybar, where I was stuck... ;-)

    – marmot
    26 mins ago



















  • How about rounded corners: addplot[rounded corners=8pt,fill=blue!60!black] coordinates {(2012,408184) (2011,408348) (2010,414870) (2009,412156)}; addplot[rounded corners=3pt,fill=red!60!black] coordinates {(2012,388950) (2011,393007) (2010,398449) (2009,395972)};?

    – marmot
    1 hour ago











  • @marmot, good idea, however the legend is than screwy ... can you fix this?

    – Zarko
    1 hour ago













  • @marmot Could we also remove the y axis and have the corresponding values at the top of histogram?

    – Amanda
    57 mins ago











  • @Zarko Yes. It took me a while to realize that the OP uses ybar interval rather than ybar, where I was stuck... ;-)

    – marmot
    26 mins ago

















How about rounded corners: addplot[rounded corners=8pt,fill=blue!60!black] coordinates {(2012,408184) (2011,408348) (2010,414870) (2009,412156)}; addplot[rounded corners=3pt,fill=red!60!black] coordinates {(2012,388950) (2011,393007) (2010,398449) (2009,395972)};?

– marmot
1 hour ago





How about rounded corners: addplot[rounded corners=8pt,fill=blue!60!black] coordinates {(2012,408184) (2011,408348) (2010,414870) (2009,412156)}; addplot[rounded corners=3pt,fill=red!60!black] coordinates {(2012,388950) (2011,393007) (2010,398449) (2009,395972)};?

– marmot
1 hour ago













@marmot, good idea, however the legend is than screwy ... can you fix this?

– Zarko
1 hour ago







@marmot, good idea, however the legend is than screwy ... can you fix this?

– Zarko
1 hour ago















@marmot Could we also remove the y axis and have the corresponding values at the top of histogram?

– Amanda
57 mins ago





@marmot Could we also remove the y axis and have the corresponding values at the top of histogram?

– Amanda
57 mins ago













@Zarko Yes. It took me a while to realize that the OP uses ybar interval rather than ybar, where I was stuck... ;-)

– marmot
26 mins ago





@Zarko Yes. It took me a while to realize that the OP uses ybar interval rather than ybar, where I was stuck... ;-)

– marmot
26 mins ago










1 Answer
1






active

oldest

votes


















6














This is a simple-minded proposal. Note that I changed from ybar interval to ybar, see here. The main idea is to use rounded corners but then one has to fix the legend to have a smaller radius of the rounded corners. I also removed the y axis and added nodes near coords, as requested.



documentclass{article}
usepackage{pgfplots}
pgfplotsset{compat=1.16}


begin{document}
begin{tikzpicture}
pgfplotsset{/pgfplots/ybar legend/.style={
/pgfplots/legend image code/.code={
draw [##1,/tikz/.cd,rounded corners=1pt,bar width=3pt,yshift=-0.2em,bar shift=0pt]
plot coordinates {(0cm,0.8em) (2*pgfplotbarwidth,0.6em)};
},
},}
begin{axis}[hide y axis,axis x line=bottom,
x tick label style={
/pgf/number format/1000 sep=},
%ylabel=Year,
enlargelimits=0.15,
legend style={at={(0.5,-0.1)}, anchor=north,legend columns=-1},
ybar,bar width=2em,
%symbolic x coords={2009,2010,2011,2012},
ybar legend,
nodes near coords=pgfmathprintnumber{pgfplotspointmeta},
every node near coord/.append style={
anchor=mid west,
rotate=70} % from https://tex.stackexchange.com/a/27143/121799
]
addplot[rounded corners=8pt,fill=blue!60!black,
]
coordinates {(2009,412156) (2010,414870) (2011,408348) (2012,408184)};
addplot [rounded corners=8pt,fill=red!60!black]
coordinates {(2009,395972) (2010,398449) (2011,393007) (2012,388950)};
legend{Men,Women}
end{axis}
end{tikzpicture}
end{document}


enter image description here






share|improve this answer


























  • Could we also remove the y axis and have the corresponding values at the top of each bar?

    – Amanda
    53 mins ago













  • thank you very much! very good answer! (+1)

    – Zarko
    22 mins ago












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


}
});






Amanda is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f488406%2fhow-to-generate-a-customised-histogram-with-pgf-plots%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









6














This is a simple-minded proposal. Note that I changed from ybar interval to ybar, see here. The main idea is to use rounded corners but then one has to fix the legend to have a smaller radius of the rounded corners. I also removed the y axis and added nodes near coords, as requested.



documentclass{article}
usepackage{pgfplots}
pgfplotsset{compat=1.16}


begin{document}
begin{tikzpicture}
pgfplotsset{/pgfplots/ybar legend/.style={
/pgfplots/legend image code/.code={
draw [##1,/tikz/.cd,rounded corners=1pt,bar width=3pt,yshift=-0.2em,bar shift=0pt]
plot coordinates {(0cm,0.8em) (2*pgfplotbarwidth,0.6em)};
},
},}
begin{axis}[hide y axis,axis x line=bottom,
x tick label style={
/pgf/number format/1000 sep=},
%ylabel=Year,
enlargelimits=0.15,
legend style={at={(0.5,-0.1)}, anchor=north,legend columns=-1},
ybar,bar width=2em,
%symbolic x coords={2009,2010,2011,2012},
ybar legend,
nodes near coords=pgfmathprintnumber{pgfplotspointmeta},
every node near coord/.append style={
anchor=mid west,
rotate=70} % from https://tex.stackexchange.com/a/27143/121799
]
addplot[rounded corners=8pt,fill=blue!60!black,
]
coordinates {(2009,412156) (2010,414870) (2011,408348) (2012,408184)};
addplot [rounded corners=8pt,fill=red!60!black]
coordinates {(2009,395972) (2010,398449) (2011,393007) (2012,388950)};
legend{Men,Women}
end{axis}
end{tikzpicture}
end{document}


enter image description here






share|improve this answer


























  • Could we also remove the y axis and have the corresponding values at the top of each bar?

    – Amanda
    53 mins ago













  • thank you very much! very good answer! (+1)

    – Zarko
    22 mins ago
















6














This is a simple-minded proposal. Note that I changed from ybar interval to ybar, see here. The main idea is to use rounded corners but then one has to fix the legend to have a smaller radius of the rounded corners. I also removed the y axis and added nodes near coords, as requested.



documentclass{article}
usepackage{pgfplots}
pgfplotsset{compat=1.16}


begin{document}
begin{tikzpicture}
pgfplotsset{/pgfplots/ybar legend/.style={
/pgfplots/legend image code/.code={
draw [##1,/tikz/.cd,rounded corners=1pt,bar width=3pt,yshift=-0.2em,bar shift=0pt]
plot coordinates {(0cm,0.8em) (2*pgfplotbarwidth,0.6em)};
},
},}
begin{axis}[hide y axis,axis x line=bottom,
x tick label style={
/pgf/number format/1000 sep=},
%ylabel=Year,
enlargelimits=0.15,
legend style={at={(0.5,-0.1)}, anchor=north,legend columns=-1},
ybar,bar width=2em,
%symbolic x coords={2009,2010,2011,2012},
ybar legend,
nodes near coords=pgfmathprintnumber{pgfplotspointmeta},
every node near coord/.append style={
anchor=mid west,
rotate=70} % from https://tex.stackexchange.com/a/27143/121799
]
addplot[rounded corners=8pt,fill=blue!60!black,
]
coordinates {(2009,412156) (2010,414870) (2011,408348) (2012,408184)};
addplot [rounded corners=8pt,fill=red!60!black]
coordinates {(2009,395972) (2010,398449) (2011,393007) (2012,388950)};
legend{Men,Women}
end{axis}
end{tikzpicture}
end{document}


enter image description here






share|improve this answer


























  • Could we also remove the y axis and have the corresponding values at the top of each bar?

    – Amanda
    53 mins ago













  • thank you very much! very good answer! (+1)

    – Zarko
    22 mins ago














6












6








6







This is a simple-minded proposal. Note that I changed from ybar interval to ybar, see here. The main idea is to use rounded corners but then one has to fix the legend to have a smaller radius of the rounded corners. I also removed the y axis and added nodes near coords, as requested.



documentclass{article}
usepackage{pgfplots}
pgfplotsset{compat=1.16}


begin{document}
begin{tikzpicture}
pgfplotsset{/pgfplots/ybar legend/.style={
/pgfplots/legend image code/.code={
draw [##1,/tikz/.cd,rounded corners=1pt,bar width=3pt,yshift=-0.2em,bar shift=0pt]
plot coordinates {(0cm,0.8em) (2*pgfplotbarwidth,0.6em)};
},
},}
begin{axis}[hide y axis,axis x line=bottom,
x tick label style={
/pgf/number format/1000 sep=},
%ylabel=Year,
enlargelimits=0.15,
legend style={at={(0.5,-0.1)}, anchor=north,legend columns=-1},
ybar,bar width=2em,
%symbolic x coords={2009,2010,2011,2012},
ybar legend,
nodes near coords=pgfmathprintnumber{pgfplotspointmeta},
every node near coord/.append style={
anchor=mid west,
rotate=70} % from https://tex.stackexchange.com/a/27143/121799
]
addplot[rounded corners=8pt,fill=blue!60!black,
]
coordinates {(2009,412156) (2010,414870) (2011,408348) (2012,408184)};
addplot [rounded corners=8pt,fill=red!60!black]
coordinates {(2009,395972) (2010,398449) (2011,393007) (2012,388950)};
legend{Men,Women}
end{axis}
end{tikzpicture}
end{document}


enter image description here






share|improve this answer















This is a simple-minded proposal. Note that I changed from ybar interval to ybar, see here. The main idea is to use rounded corners but then one has to fix the legend to have a smaller radius of the rounded corners. I also removed the y axis and added nodes near coords, as requested.



documentclass{article}
usepackage{pgfplots}
pgfplotsset{compat=1.16}


begin{document}
begin{tikzpicture}
pgfplotsset{/pgfplots/ybar legend/.style={
/pgfplots/legend image code/.code={
draw [##1,/tikz/.cd,rounded corners=1pt,bar width=3pt,yshift=-0.2em,bar shift=0pt]
plot coordinates {(0cm,0.8em) (2*pgfplotbarwidth,0.6em)};
},
},}
begin{axis}[hide y axis,axis x line=bottom,
x tick label style={
/pgf/number format/1000 sep=},
%ylabel=Year,
enlargelimits=0.15,
legend style={at={(0.5,-0.1)}, anchor=north,legend columns=-1},
ybar,bar width=2em,
%symbolic x coords={2009,2010,2011,2012},
ybar legend,
nodes near coords=pgfmathprintnumber{pgfplotspointmeta},
every node near coord/.append style={
anchor=mid west,
rotate=70} % from https://tex.stackexchange.com/a/27143/121799
]
addplot[rounded corners=8pt,fill=blue!60!black,
]
coordinates {(2009,412156) (2010,414870) (2011,408348) (2012,408184)};
addplot [rounded corners=8pt,fill=red!60!black]
coordinates {(2009,395972) (2010,398449) (2011,393007) (2012,388950)};
legend{Men,Women}
end{axis}
end{tikzpicture}
end{document}


enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited 27 mins ago

























answered 56 mins ago









marmotmarmot

123k6160300




123k6160300













  • Could we also remove the y axis and have the corresponding values at the top of each bar?

    – Amanda
    53 mins ago













  • thank you very much! very good answer! (+1)

    – Zarko
    22 mins ago



















  • Could we also remove the y axis and have the corresponding values at the top of each bar?

    – Amanda
    53 mins ago













  • thank you very much! very good answer! (+1)

    – Zarko
    22 mins ago

















Could we also remove the y axis and have the corresponding values at the top of each bar?

– Amanda
53 mins ago







Could we also remove the y axis and have the corresponding values at the top of each bar?

– Amanda
53 mins ago















thank you very much! very good answer! (+1)

– Zarko
22 mins ago





thank you very much! very good answer! (+1)

– Zarko
22 mins ago










Amanda is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















Amanda is a new contributor. Be nice, and check out our Code of Conduct.













Amanda is a new contributor. Be nice, and check out our Code of Conduct.












Amanda is a new contributor. Be nice, and check out our Code of Conduct.
















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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f488406%2fhow-to-generate-a-customised-histogram-with-pgf-plots%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

GameSpot

connect to host localhost port 22: Connection refused

Getting a Wifi WPA2 wifi connection