legend style customization in pgfplots
I have this bar graph, and I want to do 3 things:
- Remove the numbers in the bars, they are overlapping (If possible keep only one, symbolizing that both bars have the same value);
- Within the frame of the legend, enter "Data Size" and then the values of 10KB and 20KB;
- Change the y-axis value to 28
The code I'm using:
begin{tikzpicture}
begin{axis}[
ybar,
enlargelimits=0.3,
legend style={at={(0.5 ,-0.20)},
anchor=north,legend columns =-1},
ylabel ={Memory Usage (KB)},
xlabel ={Transmissions},
symbolic x coords ={10,100,250},
xtick=data,
nodes near coords ,
nodes near coords align ={vertical},
]
addplot coordinates {(10,25.4) (100,25.4) (250,25.4)};
addplot coordinates {(10,25.4) (100,25.4) (250,25.4)};
legend{10KB,20KB}
end{axis}
end{tikzpicture}
The graph I have is this:
tikz-pgf pgfplots legend
add a comment |
I have this bar graph, and I want to do 3 things:
- Remove the numbers in the bars, they are overlapping (If possible keep only one, symbolizing that both bars have the same value);
- Within the frame of the legend, enter "Data Size" and then the values of 10KB and 20KB;
- Change the y-axis value to 28
The code I'm using:
begin{tikzpicture}
begin{axis}[
ybar,
enlargelimits=0.3,
legend style={at={(0.5 ,-0.20)},
anchor=north,legend columns =-1},
ylabel ={Memory Usage (KB)},
xlabel ={Transmissions},
symbolic x coords ={10,100,250},
xtick=data,
nodes near coords ,
nodes near coords align ={vertical},
]
addplot coordinates {(10,25.4) (100,25.4) (250,25.4)};
addplot coordinates {(10,25.4) (100,25.4) (250,25.4)};
legend{10KB,20KB}
end{axis}
end{tikzpicture}
The graph I have is this:
tikz-pgf pgfplots legend
add a comment |
I have this bar graph, and I want to do 3 things:
- Remove the numbers in the bars, they are overlapping (If possible keep only one, symbolizing that both bars have the same value);
- Within the frame of the legend, enter "Data Size" and then the values of 10KB and 20KB;
- Change the y-axis value to 28
The code I'm using:
begin{tikzpicture}
begin{axis}[
ybar,
enlargelimits=0.3,
legend style={at={(0.5 ,-0.20)},
anchor=north,legend columns =-1},
ylabel ={Memory Usage (KB)},
xlabel ={Transmissions},
symbolic x coords ={10,100,250},
xtick=data,
nodes near coords ,
nodes near coords align ={vertical},
]
addplot coordinates {(10,25.4) (100,25.4) (250,25.4)};
addplot coordinates {(10,25.4) (100,25.4) (250,25.4)};
legend{10KB,20KB}
end{axis}
end{tikzpicture}
The graph I have is this:
tikz-pgf pgfplots legend
I have this bar graph, and I want to do 3 things:
- Remove the numbers in the bars, they are overlapping (If possible keep only one, symbolizing that both bars have the same value);
- Within the frame of the legend, enter "Data Size" and then the values of 10KB and 20KB;
- Change the y-axis value to 28
The code I'm using:
begin{tikzpicture}
begin{axis}[
ybar,
enlargelimits=0.3,
legend style={at={(0.5 ,-0.20)},
anchor=north,legend columns =-1},
ylabel ={Memory Usage (KB)},
xlabel ={Transmissions},
symbolic x coords ={10,100,250},
xtick=data,
nodes near coords ,
nodes near coords align ={vertical},
]
addplot coordinates {(10,25.4) (100,25.4) (250,25.4)};
addplot coordinates {(10,25.4) (100,25.4) (250,25.4)};
legend{10KB,20KB}
end{axis}
end{tikzpicture}
The graph I have is this:
tikz-pgf pgfplots legend
tikz-pgf pgfplots legend
asked Dec 29 '18 at 18:03
Mutante
223
223
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
documentclass[border = 5pt]{standalone}
usepackage{pgfplots}
begin{document}
begin{tikzpicture}
begin{axis}[
ymin = 0, ymax = 28,
ybar,
enlarge x limits=0.3,
legend style={at={(0.5 ,-0.20)},
anchor=north,legend columns =-1},
ylabel ={Memory Usage (KB)},
xlabel ={Transmissions},
symbolic x coords ={10,100,250},
xtick=data,
nodes near coords align ={vertical},
]
addlegendimage{empty legend}
addplot[nodes near coords, fill = blue!30] coordinates {(10,25.4) (100,25.4) (250,25.4)};
addplot coordinates {(10,25.4) (100,25.4) (250,25.4)};
addlegendentry{Data Size}
addlegendentry{100KB}
addlegendentry{20KB}
%legend{10KB,20KB}
end{axis}
end{tikzpicture}
end{document}
Remove
nodes near coords
Use
addlegendentry{Data Size}
Set the limit with
ymax
But how can i display only one value in the bars? See the answer from @marmot.
– Mutante
Dec 29 '18 at 18:50
@Mutante Add the option to just one of the plotsaddplot[nodes near coords, fill = blue!30] coordinates {(10,25.4) (100,25.4) (250,25.4)};
– caverac
Dec 29 '18 at 18:58
Thanks! Now it's perfect!
– Mutante
Dec 29 '18 at 19:01
add a comment |
This is just a small addendum to caverac's nice answer that shows how one may merge two nodes near coords
into one.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16}
newcounter{mynodeindex}
pgfplotsset{%based on https://tex.stackexchange.com/a/75811/121799
step nodeindex/.code={stepcounter{mynodeindex}},
name nodes near coords/.style={
every node near coord/.append style={/pgfplots/step nodeindex,
name=#1-themynodeindex,
alias=#1-last,
},
},
name nodes near coords/.default=coordnode
}
begin{document}
begin{tikzpicture}
begin{axis}[
ybar,
enlargelimits=0.3,
legend style={at={(0.5 ,-0.20)},
anchor=north,legend columns =-1},
ylabel ={Memory Usage (KB)},
xlabel ={Transmissions},
symbolic x coords ={10,100,250},
xtick=data,
nodes near coords={},
nodes near coords align ={vertical},
name nodes near coords
]
addplot coordinates {(10,28) (100,28) (250,28)};
addplot coordinates {(10,28) (100,28) (250,28)};
legend{10KB,20KB}
end{axis}
pgfmathtruncatemacro{Xmax}{themynodeindex/2}
foreach X [evaluate=X as Y using {int(X+Xmax)}] in {1,...,Xmax}
{path (coordnode-X) -- (coordnode-Y) node[midway,yshift=2pt] {28};}
end{tikzpicture}
end{document}
Didn't know aboutevery node near coord
, nice! (+1)
– caverac
Dec 29 '18 at 19:34
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
});
}
});
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%2f467818%2flegend-style-customization-in-pgfplots%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
documentclass[border = 5pt]{standalone}
usepackage{pgfplots}
begin{document}
begin{tikzpicture}
begin{axis}[
ymin = 0, ymax = 28,
ybar,
enlarge x limits=0.3,
legend style={at={(0.5 ,-0.20)},
anchor=north,legend columns =-1},
ylabel ={Memory Usage (KB)},
xlabel ={Transmissions},
symbolic x coords ={10,100,250},
xtick=data,
nodes near coords align ={vertical},
]
addlegendimage{empty legend}
addplot[nodes near coords, fill = blue!30] coordinates {(10,25.4) (100,25.4) (250,25.4)};
addplot coordinates {(10,25.4) (100,25.4) (250,25.4)};
addlegendentry{Data Size}
addlegendentry{100KB}
addlegendentry{20KB}
%legend{10KB,20KB}
end{axis}
end{tikzpicture}
end{document}
Remove
nodes near coords
Use
addlegendentry{Data Size}
Set the limit with
ymax
But how can i display only one value in the bars? See the answer from @marmot.
– Mutante
Dec 29 '18 at 18:50
@Mutante Add the option to just one of the plotsaddplot[nodes near coords, fill = blue!30] coordinates {(10,25.4) (100,25.4) (250,25.4)};
– caverac
Dec 29 '18 at 18:58
Thanks! Now it's perfect!
– Mutante
Dec 29 '18 at 19:01
add a comment |
documentclass[border = 5pt]{standalone}
usepackage{pgfplots}
begin{document}
begin{tikzpicture}
begin{axis}[
ymin = 0, ymax = 28,
ybar,
enlarge x limits=0.3,
legend style={at={(0.5 ,-0.20)},
anchor=north,legend columns =-1},
ylabel ={Memory Usage (KB)},
xlabel ={Transmissions},
symbolic x coords ={10,100,250},
xtick=data,
nodes near coords align ={vertical},
]
addlegendimage{empty legend}
addplot[nodes near coords, fill = blue!30] coordinates {(10,25.4) (100,25.4) (250,25.4)};
addplot coordinates {(10,25.4) (100,25.4) (250,25.4)};
addlegendentry{Data Size}
addlegendentry{100KB}
addlegendentry{20KB}
%legend{10KB,20KB}
end{axis}
end{tikzpicture}
end{document}
Remove
nodes near coords
Use
addlegendentry{Data Size}
Set the limit with
ymax
But how can i display only one value in the bars? See the answer from @marmot.
– Mutante
Dec 29 '18 at 18:50
@Mutante Add the option to just one of the plotsaddplot[nodes near coords, fill = blue!30] coordinates {(10,25.4) (100,25.4) (250,25.4)};
– caverac
Dec 29 '18 at 18:58
Thanks! Now it's perfect!
– Mutante
Dec 29 '18 at 19:01
add a comment |
documentclass[border = 5pt]{standalone}
usepackage{pgfplots}
begin{document}
begin{tikzpicture}
begin{axis}[
ymin = 0, ymax = 28,
ybar,
enlarge x limits=0.3,
legend style={at={(0.5 ,-0.20)},
anchor=north,legend columns =-1},
ylabel ={Memory Usage (KB)},
xlabel ={Transmissions},
symbolic x coords ={10,100,250},
xtick=data,
nodes near coords align ={vertical},
]
addlegendimage{empty legend}
addplot[nodes near coords, fill = blue!30] coordinates {(10,25.4) (100,25.4) (250,25.4)};
addplot coordinates {(10,25.4) (100,25.4) (250,25.4)};
addlegendentry{Data Size}
addlegendentry{100KB}
addlegendentry{20KB}
%legend{10KB,20KB}
end{axis}
end{tikzpicture}
end{document}
Remove
nodes near coords
Use
addlegendentry{Data Size}
Set the limit with
ymax
documentclass[border = 5pt]{standalone}
usepackage{pgfplots}
begin{document}
begin{tikzpicture}
begin{axis}[
ymin = 0, ymax = 28,
ybar,
enlarge x limits=0.3,
legend style={at={(0.5 ,-0.20)},
anchor=north,legend columns =-1},
ylabel ={Memory Usage (KB)},
xlabel ={Transmissions},
symbolic x coords ={10,100,250},
xtick=data,
nodes near coords align ={vertical},
]
addlegendimage{empty legend}
addplot[nodes near coords, fill = blue!30] coordinates {(10,25.4) (100,25.4) (250,25.4)};
addplot coordinates {(10,25.4) (100,25.4) (250,25.4)};
addlegendentry{Data Size}
addlegendentry{100KB}
addlegendentry{20KB}
%legend{10KB,20KB}
end{axis}
end{tikzpicture}
end{document}
Remove
nodes near coords
Use
addlegendentry{Data Size}
Set the limit with
ymax
edited Dec 29 '18 at 18:59
answered Dec 29 '18 at 18:36
caverac
5,7131624
5,7131624
But how can i display only one value in the bars? See the answer from @marmot.
– Mutante
Dec 29 '18 at 18:50
@Mutante Add the option to just one of the plotsaddplot[nodes near coords, fill = blue!30] coordinates {(10,25.4) (100,25.4) (250,25.4)};
– caverac
Dec 29 '18 at 18:58
Thanks! Now it's perfect!
– Mutante
Dec 29 '18 at 19:01
add a comment |
But how can i display only one value in the bars? See the answer from @marmot.
– Mutante
Dec 29 '18 at 18:50
@Mutante Add the option to just one of the plotsaddplot[nodes near coords, fill = blue!30] coordinates {(10,25.4) (100,25.4) (250,25.4)};
– caverac
Dec 29 '18 at 18:58
Thanks! Now it's perfect!
– Mutante
Dec 29 '18 at 19:01
But how can i display only one value in the bars? See the answer from @marmot.
– Mutante
Dec 29 '18 at 18:50
But how can i display only one value in the bars? See the answer from @marmot.
– Mutante
Dec 29 '18 at 18:50
@Mutante Add the option to just one of the plots
addplot[nodes near coords, fill = blue!30] coordinates {(10,25.4) (100,25.4) (250,25.4)};
– caverac
Dec 29 '18 at 18:58
@Mutante Add the option to just one of the plots
addplot[nodes near coords, fill = blue!30] coordinates {(10,25.4) (100,25.4) (250,25.4)};
– caverac
Dec 29 '18 at 18:58
Thanks! Now it's perfect!
– Mutante
Dec 29 '18 at 19:01
Thanks! Now it's perfect!
– Mutante
Dec 29 '18 at 19:01
add a comment |
This is just a small addendum to caverac's nice answer that shows how one may merge two nodes near coords
into one.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16}
newcounter{mynodeindex}
pgfplotsset{%based on https://tex.stackexchange.com/a/75811/121799
step nodeindex/.code={stepcounter{mynodeindex}},
name nodes near coords/.style={
every node near coord/.append style={/pgfplots/step nodeindex,
name=#1-themynodeindex,
alias=#1-last,
},
},
name nodes near coords/.default=coordnode
}
begin{document}
begin{tikzpicture}
begin{axis}[
ybar,
enlargelimits=0.3,
legend style={at={(0.5 ,-0.20)},
anchor=north,legend columns =-1},
ylabel ={Memory Usage (KB)},
xlabel ={Transmissions},
symbolic x coords ={10,100,250},
xtick=data,
nodes near coords={},
nodes near coords align ={vertical},
name nodes near coords
]
addplot coordinates {(10,28) (100,28) (250,28)};
addplot coordinates {(10,28) (100,28) (250,28)};
legend{10KB,20KB}
end{axis}
pgfmathtruncatemacro{Xmax}{themynodeindex/2}
foreach X [evaluate=X as Y using {int(X+Xmax)}] in {1,...,Xmax}
{path (coordnode-X) -- (coordnode-Y) node[midway,yshift=2pt] {28};}
end{tikzpicture}
end{document}
Didn't know aboutevery node near coord
, nice! (+1)
– caverac
Dec 29 '18 at 19:34
add a comment |
This is just a small addendum to caverac's nice answer that shows how one may merge two nodes near coords
into one.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16}
newcounter{mynodeindex}
pgfplotsset{%based on https://tex.stackexchange.com/a/75811/121799
step nodeindex/.code={stepcounter{mynodeindex}},
name nodes near coords/.style={
every node near coord/.append style={/pgfplots/step nodeindex,
name=#1-themynodeindex,
alias=#1-last,
},
},
name nodes near coords/.default=coordnode
}
begin{document}
begin{tikzpicture}
begin{axis}[
ybar,
enlargelimits=0.3,
legend style={at={(0.5 ,-0.20)},
anchor=north,legend columns =-1},
ylabel ={Memory Usage (KB)},
xlabel ={Transmissions},
symbolic x coords ={10,100,250},
xtick=data,
nodes near coords={},
nodes near coords align ={vertical},
name nodes near coords
]
addplot coordinates {(10,28) (100,28) (250,28)};
addplot coordinates {(10,28) (100,28) (250,28)};
legend{10KB,20KB}
end{axis}
pgfmathtruncatemacro{Xmax}{themynodeindex/2}
foreach X [evaluate=X as Y using {int(X+Xmax)}] in {1,...,Xmax}
{path (coordnode-X) -- (coordnode-Y) node[midway,yshift=2pt] {28};}
end{tikzpicture}
end{document}
Didn't know aboutevery node near coord
, nice! (+1)
– caverac
Dec 29 '18 at 19:34
add a comment |
This is just a small addendum to caverac's nice answer that shows how one may merge two nodes near coords
into one.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16}
newcounter{mynodeindex}
pgfplotsset{%based on https://tex.stackexchange.com/a/75811/121799
step nodeindex/.code={stepcounter{mynodeindex}},
name nodes near coords/.style={
every node near coord/.append style={/pgfplots/step nodeindex,
name=#1-themynodeindex,
alias=#1-last,
},
},
name nodes near coords/.default=coordnode
}
begin{document}
begin{tikzpicture}
begin{axis}[
ybar,
enlargelimits=0.3,
legend style={at={(0.5 ,-0.20)},
anchor=north,legend columns =-1},
ylabel ={Memory Usage (KB)},
xlabel ={Transmissions},
symbolic x coords ={10,100,250},
xtick=data,
nodes near coords={},
nodes near coords align ={vertical},
name nodes near coords
]
addplot coordinates {(10,28) (100,28) (250,28)};
addplot coordinates {(10,28) (100,28) (250,28)};
legend{10KB,20KB}
end{axis}
pgfmathtruncatemacro{Xmax}{themynodeindex/2}
foreach X [evaluate=X as Y using {int(X+Xmax)}] in {1,...,Xmax}
{path (coordnode-X) -- (coordnode-Y) node[midway,yshift=2pt] {28};}
end{tikzpicture}
end{document}
This is just a small addendum to caverac's nice answer that shows how one may merge two nodes near coords
into one.
documentclass[tikz,border=3.14mm]{standalone}
usepackage{pgfplots}
pgfplotsset{compat=1.16}
newcounter{mynodeindex}
pgfplotsset{%based on https://tex.stackexchange.com/a/75811/121799
step nodeindex/.code={stepcounter{mynodeindex}},
name nodes near coords/.style={
every node near coord/.append style={/pgfplots/step nodeindex,
name=#1-themynodeindex,
alias=#1-last,
},
},
name nodes near coords/.default=coordnode
}
begin{document}
begin{tikzpicture}
begin{axis}[
ybar,
enlargelimits=0.3,
legend style={at={(0.5 ,-0.20)},
anchor=north,legend columns =-1},
ylabel ={Memory Usage (KB)},
xlabel ={Transmissions},
symbolic x coords ={10,100,250},
xtick=data,
nodes near coords={},
nodes near coords align ={vertical},
name nodes near coords
]
addplot coordinates {(10,28) (100,28) (250,28)};
addplot coordinates {(10,28) (100,28) (250,28)};
legend{10KB,20KB}
end{axis}
pgfmathtruncatemacro{Xmax}{themynodeindex/2}
foreach X [evaluate=X as Y using {int(X+Xmax)}] in {1,...,Xmax}
{path (coordnode-X) -- (coordnode-Y) node[midway,yshift=2pt] {28};}
end{tikzpicture}
end{document}
answered Dec 29 '18 at 18:41
marmot
88.3k4102190
88.3k4102190
Didn't know aboutevery node near coord
, nice! (+1)
– caverac
Dec 29 '18 at 19:34
add a comment |
Didn't know aboutevery node near coord
, nice! (+1)
– caverac
Dec 29 '18 at 19:34
Didn't know about
every node near coord
, nice! (+1)– caverac
Dec 29 '18 at 19:34
Didn't know about
every node near coord
, nice! (+1)– caverac
Dec 29 '18 at 19:34
add a comment |
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%2f467818%2flegend-style-customization-in-pgfplots%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