Stacked ybar plot creates additional empty y-entries
Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
I have this code:
documentclassscrartcl
usepackagepgfplots
pgfplotsset
compat=1.16,
table/col sep=comma
usepackagefilecontents
beginfilecontents*data.csv
Type, fillA, fillC, preAllocA, preAllocC
off, 10, 20, 0, 0
tree, 4, 5, 6, 4
computed, 6, 5, 4, 8
endfilecontents*
begindocument
begintikzpicture
beginaxis[ybar stacked,
symbolic x coords=off, tree, computed,
x tick label style=rotate=45,anchor=east]
legendFillA, FillC, preAllocA, preAllocC
addplot+ table[y=fillA]data.csv;
addplot+ table[y=fillC]data.csv;
addplot+ table[y=preAllocA]data.csv;
addplot+ table[y=preAllocC]data.csv;
endaxis
endtikzpicture
enddocument
The code basically works, but creates an extra category (y-entry) for tree and computed, as can be seen here:
Why is this? How can I prevent it?
One more small question: Is there a way to get rid of the symbolic x coords and have pgfplots take the coords from the first column of the file?
Thanks Again!
pgfplots plot bar-chart
New contributor
Horus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
4
down vote
favorite
I have this code:
documentclassscrartcl
usepackagepgfplots
pgfplotsset
compat=1.16,
table/col sep=comma
usepackagefilecontents
beginfilecontents*data.csv
Type, fillA, fillC, preAllocA, preAllocC
off, 10, 20, 0, 0
tree, 4, 5, 6, 4
computed, 6, 5, 4, 8
endfilecontents*
begindocument
begintikzpicture
beginaxis[ybar stacked,
symbolic x coords=off, tree, computed,
x tick label style=rotate=45,anchor=east]
legendFillA, FillC, preAllocA, preAllocC
addplot+ table[y=fillA]data.csv;
addplot+ table[y=fillC]data.csv;
addplot+ table[y=preAllocA]data.csv;
addplot+ table[y=preAllocC]data.csv;
endaxis
endtikzpicture
enddocument
The code basically works, but creates an extra category (y-entry) for tree and computed, as can be seen here:
Why is this? How can I prevent it?
One more small question: Is there a way to get rid of the symbolic x coords and have pgfplots take the coords from the first column of the file?
Thanks Again!
pgfplots plot bar-chart
New contributor
Horus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
I have this code:
documentclassscrartcl
usepackagepgfplots
pgfplotsset
compat=1.16,
table/col sep=comma
usepackagefilecontents
beginfilecontents*data.csv
Type, fillA, fillC, preAllocA, preAllocC
off, 10, 20, 0, 0
tree, 4, 5, 6, 4
computed, 6, 5, 4, 8
endfilecontents*
begindocument
begintikzpicture
beginaxis[ybar stacked,
symbolic x coords=off, tree, computed,
x tick label style=rotate=45,anchor=east]
legendFillA, FillC, preAllocA, preAllocC
addplot+ table[y=fillA]data.csv;
addplot+ table[y=fillC]data.csv;
addplot+ table[y=preAllocA]data.csv;
addplot+ table[y=preAllocC]data.csv;
endaxis
endtikzpicture
enddocument
The code basically works, but creates an extra category (y-entry) for tree and computed, as can be seen here:
Why is this? How can I prevent it?
One more small question: Is there a way to get rid of the symbolic x coords and have pgfplots take the coords from the first column of the file?
Thanks Again!
pgfplots plot bar-chart
New contributor
Horus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I have this code:
documentclassscrartcl
usepackagepgfplots
pgfplotsset
compat=1.16,
table/col sep=comma
usepackagefilecontents
beginfilecontents*data.csv
Type, fillA, fillC, preAllocA, preAllocC
off, 10, 20, 0, 0
tree, 4, 5, 6, 4
computed, 6, 5, 4, 8
endfilecontents*
begindocument
begintikzpicture
beginaxis[ybar stacked,
symbolic x coords=off, tree, computed,
x tick label style=rotate=45,anchor=east]
legendFillA, FillC, preAllocA, preAllocC
addplot+ table[y=fillA]data.csv;
addplot+ table[y=fillC]data.csv;
addplot+ table[y=preAllocA]data.csv;
addplot+ table[y=preAllocC]data.csv;
endaxis
endtikzpicture
enddocument
The code basically works, but creates an extra category (y-entry) for tree and computed, as can be seen here:
Why is this? How can I prevent it?
One more small question: Is there a way to get rid of the symbolic x coords and have pgfplots take the coords from the first column of the file?
Thanks Again!
pgfplots plot bar-chart
New contributor
Horus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Horus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Sep 4 at 16:19
Horus
1502
1502
New contributor
Horus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Horus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Horus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
The perhaps simplest way to prevent pgfplots from adding more ticks is to add xtick=data
. See e.g. the examples on p. 97 of the manual.
documentclassscrartcl
usepackagepgfplots
pgfplotsset
compat=1.16,
table/col sep=comma
usepackagefilecontents
beginfilecontents*data.csv
Type, fillA, fillC, preAllocA, preAllocC
off, 10, 20, 0, 0
tree, 4, 5, 6, 4
computed, 6, 5, 4, 8
endfilecontents*
begindocument
begintikzpicture
beginaxis[ybar stacked,
symbolic x coords=off, tree, computed,
xtick=data,
x tick label style=rotate=45,anchor=east]
legendFillA, FillC, preAllocA, preAllocC
addplot table[y=fillA]data.csv;
addplot+ table[y=fillC]data.csv;
addplot+ table[y=preAllocA]data.csv;
addplot+ table[y=preAllocC]data.csv;
endaxis
endtikzpicture
enddocument
add a comment |Â
up vote
3
down vote
Answering also the last part, you can set xtick=0,1,2
(I first tried xtick distance=1
which would be better, but that didn't quite work, at least not on Overleaf), and then add xticklabels from table=data.csvType
to get the ticklabels from the file. Finally, in the plots use x expr
to set the x-coordinate, e.g. addplot+ table[x expr=coordindex, y=fillA]data.csv;
.
documentclassscrartcl
usepackagepgfplots
pgfplotsset
compat=1.14,% overleaf was still on 1.14, so I changed the compat-setting
table/col sep=comma
usepackagefilecontents
beginfilecontents*data.csv
Type, fillA, fillC, preAllocA, preAllocC
off, 10, 20, 0, 0
tree, 4, 5, 6, 4
computed, 6, 5, 4, 8
endfilecontents*
begindocument
begintikzpicture
beginaxis[
ybar stacked,
xtick=0,1,2, % set explicit tick positions
xticklabels from table=data.csvType, % get ticklabels from Type column
x tick label style=rotate=45,anchor=north east, % change east to north east
% just a quick suggestion for the legend layout
legend columns=2,
legend cell align=left,
legend transposed
]
legendFillA, FillC, preAllocA, preAllocC
% coordindex corresponds to row number in table, counting from 0
addplot+ table[x expr=coordindex, y=fillA]data.csv;
addplot+ table[x expr=coordindex, y=fillC]data.csv;
addplot+ table[x expr=coordindex, y=preAllocA]data.csv;
addplot+ table[x expr=coordindex, y=preAllocC]data.csv;
endaxis
endtikzpicture
enddocument
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
The perhaps simplest way to prevent pgfplots from adding more ticks is to add xtick=data
. See e.g. the examples on p. 97 of the manual.
documentclassscrartcl
usepackagepgfplots
pgfplotsset
compat=1.16,
table/col sep=comma
usepackagefilecontents
beginfilecontents*data.csv
Type, fillA, fillC, preAllocA, preAllocC
off, 10, 20, 0, 0
tree, 4, 5, 6, 4
computed, 6, 5, 4, 8
endfilecontents*
begindocument
begintikzpicture
beginaxis[ybar stacked,
symbolic x coords=off, tree, computed,
xtick=data,
x tick label style=rotate=45,anchor=east]
legendFillA, FillC, preAllocA, preAllocC
addplot table[y=fillA]data.csv;
addplot+ table[y=fillC]data.csv;
addplot+ table[y=preAllocA]data.csv;
addplot+ table[y=preAllocC]data.csv;
endaxis
endtikzpicture
enddocument
add a comment |Â
up vote
3
down vote
accepted
The perhaps simplest way to prevent pgfplots from adding more ticks is to add xtick=data
. See e.g. the examples on p. 97 of the manual.
documentclassscrartcl
usepackagepgfplots
pgfplotsset
compat=1.16,
table/col sep=comma
usepackagefilecontents
beginfilecontents*data.csv
Type, fillA, fillC, preAllocA, preAllocC
off, 10, 20, 0, 0
tree, 4, 5, 6, 4
computed, 6, 5, 4, 8
endfilecontents*
begindocument
begintikzpicture
beginaxis[ybar stacked,
symbolic x coords=off, tree, computed,
xtick=data,
x tick label style=rotate=45,anchor=east]
legendFillA, FillC, preAllocA, preAllocC
addplot table[y=fillA]data.csv;
addplot+ table[y=fillC]data.csv;
addplot+ table[y=preAllocA]data.csv;
addplot+ table[y=preAllocC]data.csv;
endaxis
endtikzpicture
enddocument
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
The perhaps simplest way to prevent pgfplots from adding more ticks is to add xtick=data
. See e.g. the examples on p. 97 of the manual.
documentclassscrartcl
usepackagepgfplots
pgfplotsset
compat=1.16,
table/col sep=comma
usepackagefilecontents
beginfilecontents*data.csv
Type, fillA, fillC, preAllocA, preAllocC
off, 10, 20, 0, 0
tree, 4, 5, 6, 4
computed, 6, 5, 4, 8
endfilecontents*
begindocument
begintikzpicture
beginaxis[ybar stacked,
symbolic x coords=off, tree, computed,
xtick=data,
x tick label style=rotate=45,anchor=east]
legendFillA, FillC, preAllocA, preAllocC
addplot table[y=fillA]data.csv;
addplot+ table[y=fillC]data.csv;
addplot+ table[y=preAllocA]data.csv;
addplot+ table[y=preAllocC]data.csv;
endaxis
endtikzpicture
enddocument
The perhaps simplest way to prevent pgfplots from adding more ticks is to add xtick=data
. See e.g. the examples on p. 97 of the manual.
documentclassscrartcl
usepackagepgfplots
pgfplotsset
compat=1.16,
table/col sep=comma
usepackagefilecontents
beginfilecontents*data.csv
Type, fillA, fillC, preAllocA, preAllocC
off, 10, 20, 0, 0
tree, 4, 5, 6, 4
computed, 6, 5, 4, 8
endfilecontents*
begindocument
begintikzpicture
beginaxis[ybar stacked,
symbolic x coords=off, tree, computed,
xtick=data,
x tick label style=rotate=45,anchor=east]
legendFillA, FillC, preAllocA, preAllocC
addplot table[y=fillA]data.csv;
addplot+ table[y=fillC]data.csv;
addplot+ table[y=preAllocA]data.csv;
addplot+ table[y=preAllocC]data.csv;
endaxis
endtikzpicture
enddocument
answered Sep 4 at 16:35


marmot
56.4k461123
56.4k461123
add a comment |Â
add a comment |Â
up vote
3
down vote
Answering also the last part, you can set xtick=0,1,2
(I first tried xtick distance=1
which would be better, but that didn't quite work, at least not on Overleaf), and then add xticklabels from table=data.csvType
to get the ticklabels from the file. Finally, in the plots use x expr
to set the x-coordinate, e.g. addplot+ table[x expr=coordindex, y=fillA]data.csv;
.
documentclassscrartcl
usepackagepgfplots
pgfplotsset
compat=1.14,% overleaf was still on 1.14, so I changed the compat-setting
table/col sep=comma
usepackagefilecontents
beginfilecontents*data.csv
Type, fillA, fillC, preAllocA, preAllocC
off, 10, 20, 0, 0
tree, 4, 5, 6, 4
computed, 6, 5, 4, 8
endfilecontents*
begindocument
begintikzpicture
beginaxis[
ybar stacked,
xtick=0,1,2, % set explicit tick positions
xticklabels from table=data.csvType, % get ticklabels from Type column
x tick label style=rotate=45,anchor=north east, % change east to north east
% just a quick suggestion for the legend layout
legend columns=2,
legend cell align=left,
legend transposed
]
legendFillA, FillC, preAllocA, preAllocC
% coordindex corresponds to row number in table, counting from 0
addplot+ table[x expr=coordindex, y=fillA]data.csv;
addplot+ table[x expr=coordindex, y=fillC]data.csv;
addplot+ table[x expr=coordindex, y=preAllocA]data.csv;
addplot+ table[x expr=coordindex, y=preAllocC]data.csv;
endaxis
endtikzpicture
enddocument
add a comment |Â
up vote
3
down vote
Answering also the last part, you can set xtick=0,1,2
(I first tried xtick distance=1
which would be better, but that didn't quite work, at least not on Overleaf), and then add xticklabels from table=data.csvType
to get the ticklabels from the file. Finally, in the plots use x expr
to set the x-coordinate, e.g. addplot+ table[x expr=coordindex, y=fillA]data.csv;
.
documentclassscrartcl
usepackagepgfplots
pgfplotsset
compat=1.14,% overleaf was still on 1.14, so I changed the compat-setting
table/col sep=comma
usepackagefilecontents
beginfilecontents*data.csv
Type, fillA, fillC, preAllocA, preAllocC
off, 10, 20, 0, 0
tree, 4, 5, 6, 4
computed, 6, 5, 4, 8
endfilecontents*
begindocument
begintikzpicture
beginaxis[
ybar stacked,
xtick=0,1,2, % set explicit tick positions
xticklabels from table=data.csvType, % get ticklabels from Type column
x tick label style=rotate=45,anchor=north east, % change east to north east
% just a quick suggestion for the legend layout
legend columns=2,
legend cell align=left,
legend transposed
]
legendFillA, FillC, preAllocA, preAllocC
% coordindex corresponds to row number in table, counting from 0
addplot+ table[x expr=coordindex, y=fillA]data.csv;
addplot+ table[x expr=coordindex, y=fillC]data.csv;
addplot+ table[x expr=coordindex, y=preAllocA]data.csv;
addplot+ table[x expr=coordindex, y=preAllocC]data.csv;
endaxis
endtikzpicture
enddocument
add a comment |Â
up vote
3
down vote
up vote
3
down vote
Answering also the last part, you can set xtick=0,1,2
(I first tried xtick distance=1
which would be better, but that didn't quite work, at least not on Overleaf), and then add xticklabels from table=data.csvType
to get the ticklabels from the file. Finally, in the plots use x expr
to set the x-coordinate, e.g. addplot+ table[x expr=coordindex, y=fillA]data.csv;
.
documentclassscrartcl
usepackagepgfplots
pgfplotsset
compat=1.14,% overleaf was still on 1.14, so I changed the compat-setting
table/col sep=comma
usepackagefilecontents
beginfilecontents*data.csv
Type, fillA, fillC, preAllocA, preAllocC
off, 10, 20, 0, 0
tree, 4, 5, 6, 4
computed, 6, 5, 4, 8
endfilecontents*
begindocument
begintikzpicture
beginaxis[
ybar stacked,
xtick=0,1,2, % set explicit tick positions
xticklabels from table=data.csvType, % get ticklabels from Type column
x tick label style=rotate=45,anchor=north east, % change east to north east
% just a quick suggestion for the legend layout
legend columns=2,
legend cell align=left,
legend transposed
]
legendFillA, FillC, preAllocA, preAllocC
% coordindex corresponds to row number in table, counting from 0
addplot+ table[x expr=coordindex, y=fillA]data.csv;
addplot+ table[x expr=coordindex, y=fillC]data.csv;
addplot+ table[x expr=coordindex, y=preAllocA]data.csv;
addplot+ table[x expr=coordindex, y=preAllocC]data.csv;
endaxis
endtikzpicture
enddocument
Answering also the last part, you can set xtick=0,1,2
(I first tried xtick distance=1
which would be better, but that didn't quite work, at least not on Overleaf), and then add xticklabels from table=data.csvType
to get the ticklabels from the file. Finally, in the plots use x expr
to set the x-coordinate, e.g. addplot+ table[x expr=coordindex, y=fillA]data.csv;
.
documentclassscrartcl
usepackagepgfplots
pgfplotsset
compat=1.14,% overleaf was still on 1.14, so I changed the compat-setting
table/col sep=comma
usepackagefilecontents
beginfilecontents*data.csv
Type, fillA, fillC, preAllocA, preAllocC
off, 10, 20, 0, 0
tree, 4, 5, 6, 4
computed, 6, 5, 4, 8
endfilecontents*
begindocument
begintikzpicture
beginaxis[
ybar stacked,
xtick=0,1,2, % set explicit tick positions
xticklabels from table=data.csvType, % get ticklabels from Type column
x tick label style=rotate=45,anchor=north east, % change east to north east
% just a quick suggestion for the legend layout
legend columns=2,
legend cell align=left,
legend transposed
]
legendFillA, FillC, preAllocA, preAllocC
% coordindex corresponds to row number in table, counting from 0
addplot+ table[x expr=coordindex, y=fillA]data.csv;
addplot+ table[x expr=coordindex, y=fillC]data.csv;
addplot+ table[x expr=coordindex, y=preAllocA]data.csv;
addplot+ table[x expr=coordindex, y=preAllocC]data.csv;
endaxis
endtikzpicture
enddocument
answered Sep 4 at 16:48
Torbjørn T.
150k13242424
150k13242424
add a comment |Â
add a comment |Â
Horus is a new contributor. Be nice, and check out our Code of Conduct.
Horus is a new contributor. Be nice, and check out our Code of Conduct.
Horus is a new contributor. Be nice, and check out our Code of Conduct.
Horus 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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f449295%2fstacked-ybar-plot-creates-additional-empty-y-entries%23new-answer', 'question_page');
);
Post as a guest
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
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
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