Linear comb plot, choosing origin different from zero












3















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:
Sample Output



If I don't do this shift, then the result looks like this (since all combs start at y = 0):
Wrong output










share|improve this question

























  • 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


















3















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:
Sample Output



If I don't do this shift, then the result looks like this (since all combs start at y = 0):
Wrong output










share|improve this question

























  • 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
















3












3








3








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:
Sample Output



If I don't do this shift, then the result looks like this (since all combs start at y = 0):
Wrong output










share|improve this question
















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:
Sample Output



If I don't do this shift, then the result looks like this (since all combs start at y = 0):
Wrong output







pgfplots






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 to log 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











  • 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



















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












1 Answer
1






active

oldest

votes


















1





+50









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}



enter image description here






share|improve this answer
























  • 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














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
});


}
});














draft saved

draft discarded


















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









1





+50









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}



enter image description here






share|improve this answer
























  • 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


















1





+50









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}



enter image description here






share|improve this answer
























  • 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
















1





+50







1





+50



1




+50





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}



enter image description here






share|improve this answer













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}



enter image description here







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 24 at 18:11









KpymKpym

17.2k24090




17.2k24090













  • 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





















  • 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



















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




















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

ComboBox Display Member on multiple fields

Is it possible to collect Nectar points via Trainline?