Keep zero in the centre of axisplotting two time series with boundsHow do i get the x axis on top but keep a line on the bottomAxis labels shifts off centre when using the xscale functionKeep position of coordinates with different axis-scaleHow to hide empty (value 0) ybars with pgfplots?pgfplots: percentage in matrix plotPlacing a zero in a pgfplots with middle axisnon linear scaling of y-axis around zeroKeep path within axis
What is the motivation behind designing a control stick that does not move?
In what language did Túrin converse with Mím?
Can I leave a large suitcase at TPE during a 4-hour layover, and pick it up 4.5 days later when I come back to TPE on my way to Taipei downtown?
Is it good practice to speed up and slow down where not written in a song?
Power supply circuit for a PIC16F88 Microchip
Tikz: Draw simplified BLE-Stack
Where should I draw the line on follow up questions from previous employer
Using font to highlight a god's speech in dialogue
Could a simple hospital oxygen mask protect from aerosol poison?
Can a human variant take proficiency in initiative?
Padding a column of lists
Welche normative Autorität hat der Duden? / What's the normative authority of the Duden?
How to Flip Rotation from Positive to Negative?
Is the following statement true: two real numbers a and b are equal iff for every ε > 0, |a − b| < ε.
I failed to respond to a potential advisor
How is the anglicism "jackpot" commonly expressed in French?
How does the search space affect the speed of an ILP solver?
How to investigate an unknown 1.5GB file named "sudo" in my Linux home directory?
How were US credit cards verified in-store in the 1980's?
Does FERPA require parental notification of disability assessment?
I was given someone else's visa, stamped in my passport
How would a disabled person earn their living in a medieval-type town?
Can two aircraft be allowed to stay on the same runway at the same time?
Can a system of three stars exist?
Keep zero in the centre of axis
plotting two time series with boundsHow do i get the x axis on top but keep a line on the bottomAxis labels shifts off centre when using the xscale functionKeep position of coordinates with different axis-scaleHow to hide empty (value 0) ybars with pgfplots?pgfplots: percentage in matrix plotPlacing a zero in a pgfplots with middle axisnon linear scaling of y-axis around zeroKeep path within axis
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want to understand if I can keep the x axis automatically "centred" around 0, i.e., having the absolute axis option values for x min and x max equal, without setting them explicitly.
The following MWE shows the issue. I have point estimates and their confidence intervals. The maximum values are -3.5 and 3.5, however, setting those to x min or x max would decrease the readability (shrink the plots).
On the other hand, comparing the point estimates would be easier if the zero was centred.
MWE:
documentclassarticle
usepackagepgfplots
beginfilecontentsdata.csv
nr est CL CU
1 -0.9 -1.3 -0.3
2 0 -0.6 0.58
endfilecontents
begindocument
begintikzpicture
beginaxis[xmajorgrids]
addplot+[only marks,error bars/.cd,x explicit,x dir=both] table [
x=est,
y = nr,
x error plus expr=thisrowCU-thisrowest,
x error minus expr=thisrowest-thisrowCL]data.csv;
endaxis
endtikzpicture
enddocument

pgfplots
add a comment |
I want to understand if I can keep the x axis automatically "centred" around 0, i.e., having the absolute axis option values for x min and x max equal, without setting them explicitly.
The following MWE shows the issue. I have point estimates and their confidence intervals. The maximum values are -3.5 and 3.5, however, setting those to x min or x max would decrease the readability (shrink the plots).
On the other hand, comparing the point estimates would be easier if the zero was centred.
MWE:
documentclassarticle
usepackagepgfplots
beginfilecontentsdata.csv
nr est CL CU
1 -0.9 -1.3 -0.3
2 0 -0.6 0.58
endfilecontents
begindocument
begintikzpicture
beginaxis[xmajorgrids]
addplot+[only marks,error bars/.cd,x explicit,x dir=both] table [
x=est,
y = nr,
x error plus expr=thisrowCU-thisrowest,
x error minus expr=thisrowest-thisrowCL]data.csv;
endaxis
endtikzpicture
enddocument

pgfplots
add a comment |
I want to understand if I can keep the x axis automatically "centred" around 0, i.e., having the absolute axis option values for x min and x max equal, without setting them explicitly.
The following MWE shows the issue. I have point estimates and their confidence intervals. The maximum values are -3.5 and 3.5, however, setting those to x min or x max would decrease the readability (shrink the plots).
On the other hand, comparing the point estimates would be easier if the zero was centred.
MWE:
documentclassarticle
usepackagepgfplots
beginfilecontentsdata.csv
nr est CL CU
1 -0.9 -1.3 -0.3
2 0 -0.6 0.58
endfilecontents
begindocument
begintikzpicture
beginaxis[xmajorgrids]
addplot+[only marks,error bars/.cd,x explicit,x dir=both] table [
x=est,
y = nr,
x error plus expr=thisrowCU-thisrowest,
x error minus expr=thisrowest-thisrowCL]data.csv;
endaxis
endtikzpicture
enddocument

pgfplots
I want to understand if I can keep the x axis automatically "centred" around 0, i.e., having the absolute axis option values for x min and x max equal, without setting them explicitly.
The following MWE shows the issue. I have point estimates and their confidence intervals. The maximum values are -3.5 and 3.5, however, setting those to x min or x max would decrease the readability (shrink the plots).
On the other hand, comparing the point estimates would be easier if the zero was centred.
MWE:
documentclassarticle
usepackagepgfplots
beginfilecontentsdata.csv
nr est CL CU
1 -0.9 -1.3 -0.3
2 0 -0.6 0.58
endfilecontents
begindocument
begintikzpicture
beginaxis[xmajorgrids]
addplot+[only marks,error bars/.cd,x explicit,x dir=both] table [
x=est,
y = nr,
x error plus expr=thisrowCU-thisrowest,
x error minus expr=thisrowest-thisrowCL]data.csv;
endaxis
endtikzpicture
enddocument

pgfplots
pgfplots
asked 8 hours ago
MarcusMarcus
2612 silver badges11 bronze badges
2612 silver badges11 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I am not sure if there is an automatic solution since pgfkeysvalueof/pgfplots/xmin and pgfkeysvalueof/pgfplots/xmax won't be set but it is easy to infer the actual values of xmin and xmax using calc. They can be used in the final plot.
documentclassarticle
usepackagefilecontents
beginfilecontents*data.csv
nr est CL CU
1 -0.9 -1.3 -0.3
2 0 -0.6 0.58
endfilecontents*
usepackagepgfplots
usetikzlibrarycalc
pgfplotssetcompat=1.16
begindocument
Step 1: measure the $x_mathrmmin$ and $x_mathrmmax$ used in the plot.
begintikzpicture
beginaxis[xmajorgrids]
addplot+[only marks,error bars/.cd,x explicit,x dir=both] table [
x=est,
y = nr,
x error plus expr=thisrowCU-thisrowest,
x error minus expr=thisrowest-thisrowCL]data.csv;
path (0,0) coordinate (O) (1,0) coordinate(X);
endaxis
path let p1=($(current axis.west)-(O)$),p2=($(current axis.east)-(O)$),
p3=($(X)-(O)$) in
pgfextrapgfmathsetmacromyxminx1/x3%
pgfmathsetmacromyxmaxx2/x3%
messagexmin=myxmin, xmax=myxmax^^J%
pgfmathsetmacronewxmin-1*max(abs(myxmin),abs(myxmax))%
xdefnewxminnewxmin%
pgfmathsetmacronewxmaxmax(abs(myxmin),abs(myxmax))%
xdefnewxmaxnewxmax;
endtikzpicture
Step 2: measure the $x_mathrmmin$ and $x_mathrmmax$ used in the plot.
begintikzpicture
beginaxis[xmajorgrids,xmin=-1.488,xmax=1.488]
addplot+[only marks,error bars/.cd,x explicit,x dir=both] table [
x=est,
y = nr,
x error plus expr=thisrowCU-thisrowest,
x error minus expr=thisrowest-thisrowCL]data.csv;
endaxis
endtikzpicture
clearpage
You can also use the computed values.
begintikzpicture
beginaxis[xmajorgrids,xmin=newxmin,xmax=newxmax]
addplot+[only marks,error bars/.cd,x explicit,x dir=both] table [
x=est,
y = nr,
x error plus expr=thisrowCU-thisrowest,
x error minus expr=thisrowest-thisrowCL]data.csv;
endaxis
endtikzpicture
enddocument

You may make it fully automatic by writing the inferred values to the aux file. I will be happy to spell this out if needed.
Of course one also put the trial plot in a savebox.
– Schrödinger's cat
3 hours ago
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%2f506472%2fkeep-zero-in-the-centre-of-axis%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 am not sure if there is an automatic solution since pgfkeysvalueof/pgfplots/xmin and pgfkeysvalueof/pgfplots/xmax won't be set but it is easy to infer the actual values of xmin and xmax using calc. They can be used in the final plot.
documentclassarticle
usepackagefilecontents
beginfilecontents*data.csv
nr est CL CU
1 -0.9 -1.3 -0.3
2 0 -0.6 0.58
endfilecontents*
usepackagepgfplots
usetikzlibrarycalc
pgfplotssetcompat=1.16
begindocument
Step 1: measure the $x_mathrmmin$ and $x_mathrmmax$ used in the plot.
begintikzpicture
beginaxis[xmajorgrids]
addplot+[only marks,error bars/.cd,x explicit,x dir=both] table [
x=est,
y = nr,
x error plus expr=thisrowCU-thisrowest,
x error minus expr=thisrowest-thisrowCL]data.csv;
path (0,0) coordinate (O) (1,0) coordinate(X);
endaxis
path let p1=($(current axis.west)-(O)$),p2=($(current axis.east)-(O)$),
p3=($(X)-(O)$) in
pgfextrapgfmathsetmacromyxminx1/x3%
pgfmathsetmacromyxmaxx2/x3%
messagexmin=myxmin, xmax=myxmax^^J%
pgfmathsetmacronewxmin-1*max(abs(myxmin),abs(myxmax))%
xdefnewxminnewxmin%
pgfmathsetmacronewxmaxmax(abs(myxmin),abs(myxmax))%
xdefnewxmaxnewxmax;
endtikzpicture
Step 2: measure the $x_mathrmmin$ and $x_mathrmmax$ used in the plot.
begintikzpicture
beginaxis[xmajorgrids,xmin=-1.488,xmax=1.488]
addplot+[only marks,error bars/.cd,x explicit,x dir=both] table [
x=est,
y = nr,
x error plus expr=thisrowCU-thisrowest,
x error minus expr=thisrowest-thisrowCL]data.csv;
endaxis
endtikzpicture
clearpage
You can also use the computed values.
begintikzpicture
beginaxis[xmajorgrids,xmin=newxmin,xmax=newxmax]
addplot+[only marks,error bars/.cd,x explicit,x dir=both] table [
x=est,
y = nr,
x error plus expr=thisrowCU-thisrowest,
x error minus expr=thisrowest-thisrowCL]data.csv;
endaxis
endtikzpicture
enddocument

You may make it fully automatic by writing the inferred values to the aux file. I will be happy to spell this out if needed.
Of course one also put the trial plot in a savebox.
– Schrödinger's cat
3 hours ago
add a comment |
I am not sure if there is an automatic solution since pgfkeysvalueof/pgfplots/xmin and pgfkeysvalueof/pgfplots/xmax won't be set but it is easy to infer the actual values of xmin and xmax using calc. They can be used in the final plot.
documentclassarticle
usepackagefilecontents
beginfilecontents*data.csv
nr est CL CU
1 -0.9 -1.3 -0.3
2 0 -0.6 0.58
endfilecontents*
usepackagepgfplots
usetikzlibrarycalc
pgfplotssetcompat=1.16
begindocument
Step 1: measure the $x_mathrmmin$ and $x_mathrmmax$ used in the plot.
begintikzpicture
beginaxis[xmajorgrids]
addplot+[only marks,error bars/.cd,x explicit,x dir=both] table [
x=est,
y = nr,
x error plus expr=thisrowCU-thisrowest,
x error minus expr=thisrowest-thisrowCL]data.csv;
path (0,0) coordinate (O) (1,0) coordinate(X);
endaxis
path let p1=($(current axis.west)-(O)$),p2=($(current axis.east)-(O)$),
p3=($(X)-(O)$) in
pgfextrapgfmathsetmacromyxminx1/x3%
pgfmathsetmacromyxmaxx2/x3%
messagexmin=myxmin, xmax=myxmax^^J%
pgfmathsetmacronewxmin-1*max(abs(myxmin),abs(myxmax))%
xdefnewxminnewxmin%
pgfmathsetmacronewxmaxmax(abs(myxmin),abs(myxmax))%
xdefnewxmaxnewxmax;
endtikzpicture
Step 2: measure the $x_mathrmmin$ and $x_mathrmmax$ used in the plot.
begintikzpicture
beginaxis[xmajorgrids,xmin=-1.488,xmax=1.488]
addplot+[only marks,error bars/.cd,x explicit,x dir=both] table [
x=est,
y = nr,
x error plus expr=thisrowCU-thisrowest,
x error minus expr=thisrowest-thisrowCL]data.csv;
endaxis
endtikzpicture
clearpage
You can also use the computed values.
begintikzpicture
beginaxis[xmajorgrids,xmin=newxmin,xmax=newxmax]
addplot+[only marks,error bars/.cd,x explicit,x dir=both] table [
x=est,
y = nr,
x error plus expr=thisrowCU-thisrowest,
x error minus expr=thisrowest-thisrowCL]data.csv;
endaxis
endtikzpicture
enddocument

You may make it fully automatic by writing the inferred values to the aux file. I will be happy to spell this out if needed.
Of course one also put the trial plot in a savebox.
– Schrödinger's cat
3 hours ago
add a comment |
I am not sure if there is an automatic solution since pgfkeysvalueof/pgfplots/xmin and pgfkeysvalueof/pgfplots/xmax won't be set but it is easy to infer the actual values of xmin and xmax using calc. They can be used in the final plot.
documentclassarticle
usepackagefilecontents
beginfilecontents*data.csv
nr est CL CU
1 -0.9 -1.3 -0.3
2 0 -0.6 0.58
endfilecontents*
usepackagepgfplots
usetikzlibrarycalc
pgfplotssetcompat=1.16
begindocument
Step 1: measure the $x_mathrmmin$ and $x_mathrmmax$ used in the plot.
begintikzpicture
beginaxis[xmajorgrids]
addplot+[only marks,error bars/.cd,x explicit,x dir=both] table [
x=est,
y = nr,
x error plus expr=thisrowCU-thisrowest,
x error minus expr=thisrowest-thisrowCL]data.csv;
path (0,0) coordinate (O) (1,0) coordinate(X);
endaxis
path let p1=($(current axis.west)-(O)$),p2=($(current axis.east)-(O)$),
p3=($(X)-(O)$) in
pgfextrapgfmathsetmacromyxminx1/x3%
pgfmathsetmacromyxmaxx2/x3%
messagexmin=myxmin, xmax=myxmax^^J%
pgfmathsetmacronewxmin-1*max(abs(myxmin),abs(myxmax))%
xdefnewxminnewxmin%
pgfmathsetmacronewxmaxmax(abs(myxmin),abs(myxmax))%
xdefnewxmaxnewxmax;
endtikzpicture
Step 2: measure the $x_mathrmmin$ and $x_mathrmmax$ used in the plot.
begintikzpicture
beginaxis[xmajorgrids,xmin=-1.488,xmax=1.488]
addplot+[only marks,error bars/.cd,x explicit,x dir=both] table [
x=est,
y = nr,
x error plus expr=thisrowCU-thisrowest,
x error minus expr=thisrowest-thisrowCL]data.csv;
endaxis
endtikzpicture
clearpage
You can also use the computed values.
begintikzpicture
beginaxis[xmajorgrids,xmin=newxmin,xmax=newxmax]
addplot+[only marks,error bars/.cd,x explicit,x dir=both] table [
x=est,
y = nr,
x error plus expr=thisrowCU-thisrowest,
x error minus expr=thisrowest-thisrowCL]data.csv;
endaxis
endtikzpicture
enddocument

You may make it fully automatic by writing the inferred values to the aux file. I will be happy to spell this out if needed.
I am not sure if there is an automatic solution since pgfkeysvalueof/pgfplots/xmin and pgfkeysvalueof/pgfplots/xmax won't be set but it is easy to infer the actual values of xmin and xmax using calc. They can be used in the final plot.
documentclassarticle
usepackagefilecontents
beginfilecontents*data.csv
nr est CL CU
1 -0.9 -1.3 -0.3
2 0 -0.6 0.58
endfilecontents*
usepackagepgfplots
usetikzlibrarycalc
pgfplotssetcompat=1.16
begindocument
Step 1: measure the $x_mathrmmin$ and $x_mathrmmax$ used in the plot.
begintikzpicture
beginaxis[xmajorgrids]
addplot+[only marks,error bars/.cd,x explicit,x dir=both] table [
x=est,
y = nr,
x error plus expr=thisrowCU-thisrowest,
x error minus expr=thisrowest-thisrowCL]data.csv;
path (0,0) coordinate (O) (1,0) coordinate(X);
endaxis
path let p1=($(current axis.west)-(O)$),p2=($(current axis.east)-(O)$),
p3=($(X)-(O)$) in
pgfextrapgfmathsetmacromyxminx1/x3%
pgfmathsetmacromyxmaxx2/x3%
messagexmin=myxmin, xmax=myxmax^^J%
pgfmathsetmacronewxmin-1*max(abs(myxmin),abs(myxmax))%
xdefnewxminnewxmin%
pgfmathsetmacronewxmaxmax(abs(myxmin),abs(myxmax))%
xdefnewxmaxnewxmax;
endtikzpicture
Step 2: measure the $x_mathrmmin$ and $x_mathrmmax$ used in the plot.
begintikzpicture
beginaxis[xmajorgrids,xmin=-1.488,xmax=1.488]
addplot+[only marks,error bars/.cd,x explicit,x dir=both] table [
x=est,
y = nr,
x error plus expr=thisrowCU-thisrowest,
x error minus expr=thisrowest-thisrowCL]data.csv;
endaxis
endtikzpicture
clearpage
You can also use the computed values.
begintikzpicture
beginaxis[xmajorgrids,xmin=newxmin,xmax=newxmax]
addplot+[only marks,error bars/.cd,x explicit,x dir=both] table [
x=est,
y = nr,
x error plus expr=thisrowCU-thisrowest,
x error minus expr=thisrowest-thisrowCL]data.csv;
endaxis
endtikzpicture
enddocument

You may make it fully automatic by writing the inferred values to the aux file. I will be happy to spell this out if needed.
answered 7 hours ago
Schrödinger's catSchrödinger's cat
3,6715 silver badges15 bronze badges
3,6715 silver badges15 bronze badges
Of course one also put the trial plot in a savebox.
– Schrödinger's cat
3 hours ago
add a comment |
Of course one also put the trial plot in a savebox.
– Schrödinger's cat
3 hours ago
Of course one also put the trial plot in a savebox.
– Schrödinger's cat
3 hours ago
Of course one also put the trial plot in a savebox.
– Schrödinger's cat
3 hours ago
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%2f506472%2fkeep-zero-in-the-centre-of-axis%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