pgfplots, line in front of marks
I could not find information on this: How can I have the line shown above/in front of the marker? Right now it is plotted behind the diamond marker in the diagram as well as in the legend.
documentclass{standalone}
usepackage{xcolor, pgfplots}
begin{document}
begin{tikzpicture}
begin{axis}
addplot[mark=square*, mark options={fill=gray}] coordinates {(1,2)(2,1)};
legend{x};
end{axis}
end{tikzpicture}
end{document}
This would be the desired case:
pgfplots
add a comment |
I could not find information on this: How can I have the line shown above/in front of the marker? Right now it is plotted behind the diamond marker in the diagram as well as in the legend.
documentclass{standalone}
usepackage{xcolor, pgfplots}
begin{document}
begin{tikzpicture}
begin{axis}
addplot[mark=square*, mark options={fill=gray}] coordinates {(1,2)(2,1)};
legend{x};
end{axis}
end{tikzpicture}
end{document}
This would be the desired case:
pgfplots
The line is drawn from (1,2) to (2,1). Can you elaborate by How can I have the line shown above the marker?
– subham soni
Feb 21 at 11:21
add a comment |
I could not find information on this: How can I have the line shown above/in front of the marker? Right now it is plotted behind the diamond marker in the diagram as well as in the legend.
documentclass{standalone}
usepackage{xcolor, pgfplots}
begin{document}
begin{tikzpicture}
begin{axis}
addplot[mark=square*, mark options={fill=gray}] coordinates {(1,2)(2,1)};
legend{x};
end{axis}
end{tikzpicture}
end{document}
This would be the desired case:
pgfplots
I could not find information on this: How can I have the line shown above/in front of the marker? Right now it is plotted behind the diamond marker in the diagram as well as in the legend.
documentclass{standalone}
usepackage{xcolor, pgfplots}
begin{document}
begin{tikzpicture}
begin{axis}
addplot[mark=square*, mark options={fill=gray}] coordinates {(1,2)(2,1)};
legend{x};
end{axis}
end{tikzpicture}
end{document}
This would be the desired case:
pgfplots
pgfplots
edited Feb 21 at 13:09
Elmar
asked Feb 21 at 10:32
ElmarElmar
134
134
The line is drawn from (1,2) to (2,1). Can you elaborate by How can I have the line shown above the marker?
– subham soni
Feb 21 at 11:21
add a comment |
The line is drawn from (1,2) to (2,1). Can you elaborate by How can I have the line shown above the marker?
– subham soni
Feb 21 at 11:21
The line is drawn from (1,2) to (2,1). Can you elaborate by How can I have the line shown above the marker?
– subham soni
Feb 21 at 11:21
The line is drawn from (1,2) to (2,1). Can you elaborate by How can I have the line shown above the marker?
– subham soni
Feb 21 at 11:21
add a comment |
2 Answers
2
active
oldest
votes
There is a straightforward part: you can get the plot as desired by using mark layer
. Just draw the marks on a layer that is behind the main plot. And then there is the part that requires tiny a bit more effort: make the legend comply. To this end, I slightly modified the legend image code
. (I do not precisely know why one has to do this but given that the legend should usually be in front of the plots, it makes sense that the stuff in the legend goes on a different layer, and thus the layer of the mark gets readjusted.)
documentclass{standalone}
usepackage{xcolor, pgfplots}
pgfplotsset{compat=1.16}
begin{document}
begin{tikzpicture}
begin{axis}[set layers,mark layer=axis background,
legend image code/.code={
draw [mark repeat=2,mark phase=2,#1] plot coordinates {
(0cm,0cm) (0.3cm,0cm) (0.6cm,0cm)};
draw [#1] (0cm,0cm) rectangle (0.5cm,0cm);
}]
addplot[mark=square*, mark options={fill=gray}] coordinates {(1,2)(2,1)};
legend{x};
end{axis}
end{tikzpicture}
end{document}
Great, that'll do. Many thanks!
– Elmar
Feb 22 at 8:30
add a comment |
Welcome to TeX.SE!
If you plot the points (but by tikz node
and not pgfplot's mark
) before adding the plot it is easy:
documentclass{standalone}
usepackage{xcolor, pgfplots}
usetikzlibrary{shapes}
begin{document}
begin{tikzpicture}
begin{axis}
node[diamond,fill,color=orange,inner sep=2pt] at (axis cs:1,2) {};
node[diamond,fill,color=red,inner sep=2pt] at (axis cs:2,1) {};
node[diamond,fill,color=green,inner sep=2pt] at (axis cs:1.8,1.2) {};
addplot[thick] coordinates {(1,2)(2,1)};
legend{x};
end{axis}
end{tikzpicture}
end{document}
PS: I am sure that pgfplots
has a way too, but I don't really use it, so wait for another answer before accepting because I use mostly tikz
and no pgfplots
This is partly what I am looking for. Within the plot, the line now appears above the markers (even though it is a bit inconvenient not to have only one plot command for this simple line). However, I as well need to have the line AND symbol in the legend (again, the line overlying the mark).
– Elmar
Feb 21 at 12:05
@Elmar, I am not using pgfplots and just know some basics on it... I use tikz and creating the legend with tikz commands myself.... So, you can wait for someone that uses pgfplots and can possibly solve completely your problem. I am leaving the answer as it is to help people that possibly will find it usefull
– koleygr
Feb 21 at 12:36
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%2f475973%2fpgfplots-line-in-front-of-marks%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
There is a straightforward part: you can get the plot as desired by using mark layer
. Just draw the marks on a layer that is behind the main plot. And then there is the part that requires tiny a bit more effort: make the legend comply. To this end, I slightly modified the legend image code
. (I do not precisely know why one has to do this but given that the legend should usually be in front of the plots, it makes sense that the stuff in the legend goes on a different layer, and thus the layer of the mark gets readjusted.)
documentclass{standalone}
usepackage{xcolor, pgfplots}
pgfplotsset{compat=1.16}
begin{document}
begin{tikzpicture}
begin{axis}[set layers,mark layer=axis background,
legend image code/.code={
draw [mark repeat=2,mark phase=2,#1] plot coordinates {
(0cm,0cm) (0.3cm,0cm) (0.6cm,0cm)};
draw [#1] (0cm,0cm) rectangle (0.5cm,0cm);
}]
addplot[mark=square*, mark options={fill=gray}] coordinates {(1,2)(2,1)};
legend{x};
end{axis}
end{tikzpicture}
end{document}
Great, that'll do. Many thanks!
– Elmar
Feb 22 at 8:30
add a comment |
There is a straightforward part: you can get the plot as desired by using mark layer
. Just draw the marks on a layer that is behind the main plot. And then there is the part that requires tiny a bit more effort: make the legend comply. To this end, I slightly modified the legend image code
. (I do not precisely know why one has to do this but given that the legend should usually be in front of the plots, it makes sense that the stuff in the legend goes on a different layer, and thus the layer of the mark gets readjusted.)
documentclass{standalone}
usepackage{xcolor, pgfplots}
pgfplotsset{compat=1.16}
begin{document}
begin{tikzpicture}
begin{axis}[set layers,mark layer=axis background,
legend image code/.code={
draw [mark repeat=2,mark phase=2,#1] plot coordinates {
(0cm,0cm) (0.3cm,0cm) (0.6cm,0cm)};
draw [#1] (0cm,0cm) rectangle (0.5cm,0cm);
}]
addplot[mark=square*, mark options={fill=gray}] coordinates {(1,2)(2,1)};
legend{x};
end{axis}
end{tikzpicture}
end{document}
Great, that'll do. Many thanks!
– Elmar
Feb 22 at 8:30
add a comment |
There is a straightforward part: you can get the plot as desired by using mark layer
. Just draw the marks on a layer that is behind the main plot. And then there is the part that requires tiny a bit more effort: make the legend comply. To this end, I slightly modified the legend image code
. (I do not precisely know why one has to do this but given that the legend should usually be in front of the plots, it makes sense that the stuff in the legend goes on a different layer, and thus the layer of the mark gets readjusted.)
documentclass{standalone}
usepackage{xcolor, pgfplots}
pgfplotsset{compat=1.16}
begin{document}
begin{tikzpicture}
begin{axis}[set layers,mark layer=axis background,
legend image code/.code={
draw [mark repeat=2,mark phase=2,#1] plot coordinates {
(0cm,0cm) (0.3cm,0cm) (0.6cm,0cm)};
draw [#1] (0cm,0cm) rectangle (0.5cm,0cm);
}]
addplot[mark=square*, mark options={fill=gray}] coordinates {(1,2)(2,1)};
legend{x};
end{axis}
end{tikzpicture}
end{document}
There is a straightforward part: you can get the plot as desired by using mark layer
. Just draw the marks on a layer that is behind the main plot. And then there is the part that requires tiny a bit more effort: make the legend comply. To this end, I slightly modified the legend image code
. (I do not precisely know why one has to do this but given that the legend should usually be in front of the plots, it makes sense that the stuff in the legend goes on a different layer, and thus the layer of the mark gets readjusted.)
documentclass{standalone}
usepackage{xcolor, pgfplots}
pgfplotsset{compat=1.16}
begin{document}
begin{tikzpicture}
begin{axis}[set layers,mark layer=axis background,
legend image code/.code={
draw [mark repeat=2,mark phase=2,#1] plot coordinates {
(0cm,0cm) (0.3cm,0cm) (0.6cm,0cm)};
draw [#1] (0cm,0cm) rectangle (0.5cm,0cm);
}]
addplot[mark=square*, mark options={fill=gray}] coordinates {(1,2)(2,1)};
legend{x};
end{axis}
end{tikzpicture}
end{document}
answered Feb 21 at 16:29
marmotmarmot
104k4124236
104k4124236
Great, that'll do. Many thanks!
– Elmar
Feb 22 at 8:30
add a comment |
Great, that'll do. Many thanks!
– Elmar
Feb 22 at 8:30
Great, that'll do. Many thanks!
– Elmar
Feb 22 at 8:30
Great, that'll do. Many thanks!
– Elmar
Feb 22 at 8:30
add a comment |
Welcome to TeX.SE!
If you plot the points (but by tikz node
and not pgfplot's mark
) before adding the plot it is easy:
documentclass{standalone}
usepackage{xcolor, pgfplots}
usetikzlibrary{shapes}
begin{document}
begin{tikzpicture}
begin{axis}
node[diamond,fill,color=orange,inner sep=2pt] at (axis cs:1,2) {};
node[diamond,fill,color=red,inner sep=2pt] at (axis cs:2,1) {};
node[diamond,fill,color=green,inner sep=2pt] at (axis cs:1.8,1.2) {};
addplot[thick] coordinates {(1,2)(2,1)};
legend{x};
end{axis}
end{tikzpicture}
end{document}
PS: I am sure that pgfplots
has a way too, but I don't really use it, so wait for another answer before accepting because I use mostly tikz
and no pgfplots
This is partly what I am looking for. Within the plot, the line now appears above the markers (even though it is a bit inconvenient not to have only one plot command for this simple line). However, I as well need to have the line AND symbol in the legend (again, the line overlying the mark).
– Elmar
Feb 21 at 12:05
@Elmar, I am not using pgfplots and just know some basics on it... I use tikz and creating the legend with tikz commands myself.... So, you can wait for someone that uses pgfplots and can possibly solve completely your problem. I am leaving the answer as it is to help people that possibly will find it usefull
– koleygr
Feb 21 at 12:36
add a comment |
Welcome to TeX.SE!
If you plot the points (but by tikz node
and not pgfplot's mark
) before adding the plot it is easy:
documentclass{standalone}
usepackage{xcolor, pgfplots}
usetikzlibrary{shapes}
begin{document}
begin{tikzpicture}
begin{axis}
node[diamond,fill,color=orange,inner sep=2pt] at (axis cs:1,2) {};
node[diamond,fill,color=red,inner sep=2pt] at (axis cs:2,1) {};
node[diamond,fill,color=green,inner sep=2pt] at (axis cs:1.8,1.2) {};
addplot[thick] coordinates {(1,2)(2,1)};
legend{x};
end{axis}
end{tikzpicture}
end{document}
PS: I am sure that pgfplots
has a way too, but I don't really use it, so wait for another answer before accepting because I use mostly tikz
and no pgfplots
This is partly what I am looking for. Within the plot, the line now appears above the markers (even though it is a bit inconvenient not to have only one plot command for this simple line). However, I as well need to have the line AND symbol in the legend (again, the line overlying the mark).
– Elmar
Feb 21 at 12:05
@Elmar, I am not using pgfplots and just know some basics on it... I use tikz and creating the legend with tikz commands myself.... So, you can wait for someone that uses pgfplots and can possibly solve completely your problem. I am leaving the answer as it is to help people that possibly will find it usefull
– koleygr
Feb 21 at 12:36
add a comment |
Welcome to TeX.SE!
If you plot the points (but by tikz node
and not pgfplot's mark
) before adding the plot it is easy:
documentclass{standalone}
usepackage{xcolor, pgfplots}
usetikzlibrary{shapes}
begin{document}
begin{tikzpicture}
begin{axis}
node[diamond,fill,color=orange,inner sep=2pt] at (axis cs:1,2) {};
node[diamond,fill,color=red,inner sep=2pt] at (axis cs:2,1) {};
node[diamond,fill,color=green,inner sep=2pt] at (axis cs:1.8,1.2) {};
addplot[thick] coordinates {(1,2)(2,1)};
legend{x};
end{axis}
end{tikzpicture}
end{document}
PS: I am sure that pgfplots
has a way too, but I don't really use it, so wait for another answer before accepting because I use mostly tikz
and no pgfplots
Welcome to TeX.SE!
If you plot the points (but by tikz node
and not pgfplot's mark
) before adding the plot it is easy:
documentclass{standalone}
usepackage{xcolor, pgfplots}
usetikzlibrary{shapes}
begin{document}
begin{tikzpicture}
begin{axis}
node[diamond,fill,color=orange,inner sep=2pt] at (axis cs:1,2) {};
node[diamond,fill,color=red,inner sep=2pt] at (axis cs:2,1) {};
node[diamond,fill,color=green,inner sep=2pt] at (axis cs:1.8,1.2) {};
addplot[thick] coordinates {(1,2)(2,1)};
legend{x};
end{axis}
end{tikzpicture}
end{document}
PS: I am sure that pgfplots
has a way too, but I don't really use it, so wait for another answer before accepting because I use mostly tikz
and no pgfplots
answered Feb 21 at 11:42
koleygrkoleygr
11.4k11038
11.4k11038
This is partly what I am looking for. Within the plot, the line now appears above the markers (even though it is a bit inconvenient not to have only one plot command for this simple line). However, I as well need to have the line AND symbol in the legend (again, the line overlying the mark).
– Elmar
Feb 21 at 12:05
@Elmar, I am not using pgfplots and just know some basics on it... I use tikz and creating the legend with tikz commands myself.... So, you can wait for someone that uses pgfplots and can possibly solve completely your problem. I am leaving the answer as it is to help people that possibly will find it usefull
– koleygr
Feb 21 at 12:36
add a comment |
This is partly what I am looking for. Within the plot, the line now appears above the markers (even though it is a bit inconvenient not to have only one plot command for this simple line). However, I as well need to have the line AND symbol in the legend (again, the line overlying the mark).
– Elmar
Feb 21 at 12:05
@Elmar, I am not using pgfplots and just know some basics on it... I use tikz and creating the legend with tikz commands myself.... So, you can wait for someone that uses pgfplots and can possibly solve completely your problem. I am leaving the answer as it is to help people that possibly will find it usefull
– koleygr
Feb 21 at 12:36
This is partly what I am looking for. Within the plot, the line now appears above the markers (even though it is a bit inconvenient not to have only one plot command for this simple line). However, I as well need to have the line AND symbol in the legend (again, the line overlying the mark).
– Elmar
Feb 21 at 12:05
This is partly what I am looking for. Within the plot, the line now appears above the markers (even though it is a bit inconvenient not to have only one plot command for this simple line). However, I as well need to have the line AND symbol in the legend (again, the line overlying the mark).
– Elmar
Feb 21 at 12:05
@Elmar, I am not using pgfplots and just know some basics on it... I use tikz and creating the legend with tikz commands myself.... So, you can wait for someone that uses pgfplots and can possibly solve completely your problem. I am leaving the answer as it is to help people that possibly will find it usefull
– koleygr
Feb 21 at 12:36
@Elmar, I am not using pgfplots and just know some basics on it... I use tikz and creating the legend with tikz commands myself.... So, you can wait for someone that uses pgfplots and can possibly solve completely your problem. I am leaving the answer as it is to help people that possibly will find it usefull
– koleygr
Feb 21 at 12:36
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.
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%2f475973%2fpgfplots-line-in-front-of-marks%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
The line is drawn from (1,2) to (2,1). Can you elaborate by How can I have the line shown above the marker?
– subham soni
Feb 21 at 11:21