Linear comb plot, choosing origin different from zero
I'm plotting spectral data, sometimes with logarithmic axes and sometimes linear but with values in dB. The usual way for plotting these kind of diagrams (at least in my field) is to have all the lines start at the lower part of the graph, despite their values (negative, positive).
For logarithmic comb plots, this can easily be achieved using log origin = infty
. However, how can I use something like this for plots with negative values (in linear scale)?
Currently, I'm shifting all points up by the smallest value and then shifting all yticklabels. However, this is cumbersome and not really an automatic solution. I have to find the smallest value by hand in order to find the optimal shift. Can this be improved?
I've found this answer, but this is about logarithmic plots. I don't really understand the code, so I don't know if this can easily be modified.
Here is a MWE with what I'm trying to achieve:
documentclass{article}
usepackage{pgfplots}
begin{document}
begin{tikzpicture}
begin{axis}
[
% I'm using this:
yticklabel = {pgfmathparse{tick-130}pgfmathprintnumber{pgfmathresult}},
y filter/.expression = {y + 130},
ymin = 0
% I would like to have this:
% comb origin = -infty % or something
]
addplot[ycomb] coordinates {
(1, -6)
(2, -80)
(3, -85)
(4, -120)
(5, -120)
(6, -120)
(7, -120)
(8, -120)
(9, -120)
};
end{axis}
end{tikzpicture}
end{document}
And the result looks like this:
If I don't do this shift, then the result looks like this (since all combs start at y = 0):
pgfplots
add a comment |
I'm plotting spectral data, sometimes with logarithmic axes and sometimes linear but with values in dB. The usual way for plotting these kind of diagrams (at least in my field) is to have all the lines start at the lower part of the graph, despite their values (negative, positive).
For logarithmic comb plots, this can easily be achieved using log origin = infty
. However, how can I use something like this for plots with negative values (in linear scale)?
Currently, I'm shifting all points up by the smallest value and then shifting all yticklabels. However, this is cumbersome and not really an automatic solution. I have to find the smallest value by hand in order to find the optimal shift. Can this be improved?
I've found this answer, but this is about logarithmic plots. I don't really understand the code, so I don't know if this can easily be modified.
Here is a MWE with what I'm trying to achieve:
documentclass{article}
usepackage{pgfplots}
begin{document}
begin{tikzpicture}
begin{axis}
[
% I'm using this:
yticklabel = {pgfmathparse{tick-130}pgfmathprintnumber{pgfmathresult}},
y filter/.expression = {y + 130},
ymin = 0
% I would like to have this:
% comb origin = -infty % or something
]
addplot[ycomb] coordinates {
(1, -6)
(2, -80)
(3, -85)
(4, -120)
(5, -120)
(6, -120)
(7, -120)
(8, -120)
(9, -120)
};
end{axis}
end{tikzpicture}
end{document}
And the result looks like this:
If I don't do this shift, then the result looks like this (since all combs start at y = 0):
pgfplots
I read this question several times and still do not understand what you are asking. Could you please consider making your question clearer? E.g. by adding a sketch of the target output? (The way I read your question you already have achieved your target output.)
– marmot
Mar 23 at 1:13
Yes, what I am showing is the target output. I would like to have a key for linear comb plots to change the starting line (baseline?) for them, similar tolog origin
. I will add a picture of the unwanted output to the question.
– pschulz
Mar 23 at 9:17
add a comment |
I'm plotting spectral data, sometimes with logarithmic axes and sometimes linear but with values in dB. The usual way for plotting these kind of diagrams (at least in my field) is to have all the lines start at the lower part of the graph, despite their values (negative, positive).
For logarithmic comb plots, this can easily be achieved using log origin = infty
. However, how can I use something like this for plots with negative values (in linear scale)?
Currently, I'm shifting all points up by the smallest value and then shifting all yticklabels. However, this is cumbersome and not really an automatic solution. I have to find the smallest value by hand in order to find the optimal shift. Can this be improved?
I've found this answer, but this is about logarithmic plots. I don't really understand the code, so I don't know if this can easily be modified.
Here is a MWE with what I'm trying to achieve:
documentclass{article}
usepackage{pgfplots}
begin{document}
begin{tikzpicture}
begin{axis}
[
% I'm using this:
yticklabel = {pgfmathparse{tick-130}pgfmathprintnumber{pgfmathresult}},
y filter/.expression = {y + 130},
ymin = 0
% I would like to have this:
% comb origin = -infty % or something
]
addplot[ycomb] coordinates {
(1, -6)
(2, -80)
(3, -85)
(4, -120)
(5, -120)
(6, -120)
(7, -120)
(8, -120)
(9, -120)
};
end{axis}
end{tikzpicture}
end{document}
And the result looks like this:
If I don't do this shift, then the result looks like this (since all combs start at y = 0):
pgfplots
I'm plotting spectral data, sometimes with logarithmic axes and sometimes linear but with values in dB. The usual way for plotting these kind of diagrams (at least in my field) is to have all the lines start at the lower part of the graph, despite their values (negative, positive).
For logarithmic comb plots, this can easily be achieved using log origin = infty
. However, how can I use something like this for plots with negative values (in linear scale)?
Currently, I'm shifting all points up by the smallest value and then shifting all yticklabels. However, this is cumbersome and not really an automatic solution. I have to find the smallest value by hand in order to find the optimal shift. Can this be improved?
I've found this answer, but this is about logarithmic plots. I don't really understand the code, so I don't know if this can easily be modified.
Here is a MWE with what I'm trying to achieve:
documentclass{article}
usepackage{pgfplots}
begin{document}
begin{tikzpicture}
begin{axis}
[
% I'm using this:
yticklabel = {pgfmathparse{tick-130}pgfmathprintnumber{pgfmathresult}},
y filter/.expression = {y + 130},
ymin = 0
% I would like to have this:
% comb origin = -infty % or something
]
addplot[ycomb] coordinates {
(1, -6)
(2, -80)
(3, -85)
(4, -120)
(5, -120)
(6, -120)
(7, -120)
(8, -120)
(9, -120)
};
end{axis}
end{tikzpicture}
end{document}
And the result looks like this:
If I don't do this shift, then the result looks like this (since all combs start at y = 0):
pgfplots
pgfplots
edited Mar 23 at 9:18
pschulz
asked Mar 20 at 12:05
pschulzpschulz
970718
970718
I read this question several times and still do not understand what you are asking. Could you please consider making your question clearer? E.g. by adding a sketch of the target output? (The way I read your question you already have achieved your target output.)
– marmot
Mar 23 at 1:13
Yes, what I am showing is the target output. I would like to have a key for linear comb plots to change the starting line (baseline?) for them, similar tolog origin
. I will add a picture of the unwanted output to the question.
– pschulz
Mar 23 at 9:17
add a comment |
I read this question several times and still do not understand what you are asking. Could you please consider making your question clearer? E.g. by adding a sketch of the target output? (The way I read your question you already have achieved your target output.)
– marmot
Mar 23 at 1:13
Yes, what I am showing is the target output. I would like to have a key for linear comb plots to change the starting line (baseline?) for them, similar tolog origin
. I will add a picture of the unwanted output to the question.
– pschulz
Mar 23 at 9:17
I read this question several times and still do not understand what you are asking. Could you please consider making your question clearer? E.g. by adding a sketch of the target output? (The way I read your question you already have achieved your target output.)
– marmot
Mar 23 at 1:13
I read this question several times and still do not understand what you are asking. Could you please consider making your question clearer? E.g. by adding a sketch of the target output? (The way I read your question you already have achieved your target output.)
– marmot
Mar 23 at 1:13
Yes, what I am showing is the target output. I would like to have a key for linear comb plots to change the starting line (baseline?) for them, similar to
log origin
. I will add a picture of the unwanted output to the question.– pschulz
Mar 23 at 9:17
Yes, what I am showing is the target output. I would like to have a key for linear comb plots to change the starting line (baseline?) for them, similar to
log origin
. I will add a picture of the unwanted output to the question.– pschulz
Mar 23 at 9:17
add a comment |
1 Answer
1
active
oldest
votes
I think that you can use one "very big number" as replacement of infinity. Here I use 1000
for the value of verybignumber
. Then I apply your code with verybignumber
in place of 130
and I let pgfplots
to set ymin
.
documentclass[border=7pt]{standalone}
usepackage{pgfplots}
defverybignumber{1000}
begin{document}
begin{tikzpicture}
begin{axis}
[
yticklabel = {pgfmathparse{tick-verybignumber}pgfmathprintnumber{pgfmathresult}},
y filter/.expression = {verybignumber+y},
]
addplot[ycomb] coordinates {
(1, -6)
(2, -80)
(3, -85)
(4, -120)
(5, -120)
(6, -120)
(7, -120)
(8, -120)
(9, -120)
};
end{axis}
end{tikzpicture}
end{document}
Ah, interesting. I thought I tried something like this, but the explicit setting ofymin
messes things up. I used this because the lines started 'hovering' over the lower axis line, but with a number very different from the lowest value this works. Thanks!
– pschulz
Mar 24 at 20:27
I made a key of this for my settings:comb origin infty/.style = { yticklabel = {pgfmathparse{tick-1000}pgfmathprintnumber{pgfmathresult}}, y filter/.expression = {y + 1000} }
– pschulz
Mar 24 at 20:28
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%2f480472%2flinear-comb-plot-choosing-origin-different-from-zero%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
I think that you can use one "very big number" as replacement of infinity. Here I use 1000
for the value of verybignumber
. Then I apply your code with verybignumber
in place of 130
and I let pgfplots
to set ymin
.
documentclass[border=7pt]{standalone}
usepackage{pgfplots}
defverybignumber{1000}
begin{document}
begin{tikzpicture}
begin{axis}
[
yticklabel = {pgfmathparse{tick-verybignumber}pgfmathprintnumber{pgfmathresult}},
y filter/.expression = {verybignumber+y},
]
addplot[ycomb] coordinates {
(1, -6)
(2, -80)
(3, -85)
(4, -120)
(5, -120)
(6, -120)
(7, -120)
(8, -120)
(9, -120)
};
end{axis}
end{tikzpicture}
end{document}
Ah, interesting. I thought I tried something like this, but the explicit setting ofymin
messes things up. I used this because the lines started 'hovering' over the lower axis line, but with a number very different from the lowest value this works. Thanks!
– pschulz
Mar 24 at 20:27
I made a key of this for my settings:comb origin infty/.style = { yticklabel = {pgfmathparse{tick-1000}pgfmathprintnumber{pgfmathresult}}, y filter/.expression = {y + 1000} }
– pschulz
Mar 24 at 20:28
add a comment |
I think that you can use one "very big number" as replacement of infinity. Here I use 1000
for the value of verybignumber
. Then I apply your code with verybignumber
in place of 130
and I let pgfplots
to set ymin
.
documentclass[border=7pt]{standalone}
usepackage{pgfplots}
defverybignumber{1000}
begin{document}
begin{tikzpicture}
begin{axis}
[
yticklabel = {pgfmathparse{tick-verybignumber}pgfmathprintnumber{pgfmathresult}},
y filter/.expression = {verybignumber+y},
]
addplot[ycomb] coordinates {
(1, -6)
(2, -80)
(3, -85)
(4, -120)
(5, -120)
(6, -120)
(7, -120)
(8, -120)
(9, -120)
};
end{axis}
end{tikzpicture}
end{document}
Ah, interesting. I thought I tried something like this, but the explicit setting ofymin
messes things up. I used this because the lines started 'hovering' over the lower axis line, but with a number very different from the lowest value this works. Thanks!
– pschulz
Mar 24 at 20:27
I made a key of this for my settings:comb origin infty/.style = { yticklabel = {pgfmathparse{tick-1000}pgfmathprintnumber{pgfmathresult}}, y filter/.expression = {y + 1000} }
– pschulz
Mar 24 at 20:28
add a comment |
I think that you can use one "very big number" as replacement of infinity. Here I use 1000
for the value of verybignumber
. Then I apply your code with verybignumber
in place of 130
and I let pgfplots
to set ymin
.
documentclass[border=7pt]{standalone}
usepackage{pgfplots}
defverybignumber{1000}
begin{document}
begin{tikzpicture}
begin{axis}
[
yticklabel = {pgfmathparse{tick-verybignumber}pgfmathprintnumber{pgfmathresult}},
y filter/.expression = {verybignumber+y},
]
addplot[ycomb] coordinates {
(1, -6)
(2, -80)
(3, -85)
(4, -120)
(5, -120)
(6, -120)
(7, -120)
(8, -120)
(9, -120)
};
end{axis}
end{tikzpicture}
end{document}
I think that you can use one "very big number" as replacement of infinity. Here I use 1000
for the value of verybignumber
. Then I apply your code with verybignumber
in place of 130
and I let pgfplots
to set ymin
.
documentclass[border=7pt]{standalone}
usepackage{pgfplots}
defverybignumber{1000}
begin{document}
begin{tikzpicture}
begin{axis}
[
yticklabel = {pgfmathparse{tick-verybignumber}pgfmathprintnumber{pgfmathresult}},
y filter/.expression = {verybignumber+y},
]
addplot[ycomb] coordinates {
(1, -6)
(2, -80)
(3, -85)
(4, -120)
(5, -120)
(6, -120)
(7, -120)
(8, -120)
(9, -120)
};
end{axis}
end{tikzpicture}
end{document}
answered Mar 24 at 18:11
KpymKpym
17.2k24090
17.2k24090
Ah, interesting. I thought I tried something like this, but the explicit setting ofymin
messes things up. I used this because the lines started 'hovering' over the lower axis line, but with a number very different from the lowest value this works. Thanks!
– pschulz
Mar 24 at 20:27
I made a key of this for my settings:comb origin infty/.style = { yticklabel = {pgfmathparse{tick-1000}pgfmathprintnumber{pgfmathresult}}, y filter/.expression = {y + 1000} }
– pschulz
Mar 24 at 20:28
add a comment |
Ah, interesting. I thought I tried something like this, but the explicit setting ofymin
messes things up. I used this because the lines started 'hovering' over the lower axis line, but with a number very different from the lowest value this works. Thanks!
– pschulz
Mar 24 at 20:27
I made a key of this for my settings:comb origin infty/.style = { yticklabel = {pgfmathparse{tick-1000}pgfmathprintnumber{pgfmathresult}}, y filter/.expression = {y + 1000} }
– pschulz
Mar 24 at 20:28
Ah, interesting. I thought I tried something like this, but the explicit setting of
ymin
messes things up. I used this because the lines started 'hovering' over the lower axis line, but with a number very different from the lowest value this works. Thanks!– pschulz
Mar 24 at 20:27
Ah, interesting. I thought I tried something like this, but the explicit setting of
ymin
messes things up. I used this because the lines started 'hovering' over the lower axis line, but with a number very different from the lowest value this works. Thanks!– pschulz
Mar 24 at 20:27
I made a key of this for my settings:
comb origin infty/.style = { yticklabel = {pgfmathparse{tick-1000}pgfmathprintnumber{pgfmathresult}}, y filter/.expression = {y + 1000} }
– pschulz
Mar 24 at 20:28
I made a key of this for my settings:
comb origin infty/.style = { yticklabel = {pgfmathparse{tick-1000}pgfmathprintnumber{pgfmathresult}}, y filter/.expression = {y + 1000} }
– pschulz
Mar 24 at 20:28
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%2f480472%2flinear-comb-plot-choosing-origin-different-from-zero%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
I read this question several times and still do not understand what you are asking. Could you please consider making your question clearer? E.g. by adding a sketch of the target output? (The way I read your question you already have achieved your target output.)
– marmot
Mar 23 at 1:13
Yes, what I am showing is the target output. I would like to have a key for linear comb plots to change the starting line (baseline?) for them, similar to
log origin
. I will add a picture of the unwanted output to the question.– pschulz
Mar 23 at 9:17