How to generate a customised histogram with pgf plots?
I am trying to generate a histogram like the following:
While going through the examples pgf plots, I was able to generate a histogram similar to the following:
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
New contributor
add a comment |
I am trying to generate a histogram like the following:
While going through the examples pgf plots, I was able to generate a histogram similar to the following:
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
New contributor
How aboutrounded 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 they
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 usesybar interval
rather thanybar
, where I was stuck... ;-)
– marmot
26 mins ago
add a comment |
I am trying to generate a histogram like the following:
While going through the examples pgf plots, I was able to generate a histogram similar to the following:
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
New contributor
I am trying to generate a histogram like the following:
While going through the examples pgf plots, I was able to generate a histogram similar to the following:
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
tikz-pgf pgfplots histogram
New contributor
New contributor
New contributor
asked 1 hour ago
AmandaAmanda
474
474
New contributor
New contributor
How aboutrounded 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 they
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 usesybar interval
rather thanybar
, where I was stuck... ;-)
– marmot
26 mins ago
add a comment |
How aboutrounded 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 they
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 usesybar interval
rather thanybar
, 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
add a comment |
1 Answer
1
active
oldest
votes
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}
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
add a comment |
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.
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%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
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}
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
add a comment |
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}
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
add a comment |
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}
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}
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
add a comment |
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
add a comment |
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.
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.
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%2f488406%2fhow-to-generate-a-customised-histogram-with-pgf-plots%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
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 thanybar
, where I was stuck... ;-)– marmot
26 mins ago