Put grid below plot in pgfplots
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
In a plot with pgfplots I would like to draw, from background to foreground, in the following order:
- (background) grid;
- (intermediate layer) plot;
- (foreground) axis.
As specified in this answer,
Adding
axis on top
to the axis options means axis lines, ticks and
grids are printed on top of the stuff inside the environment.
So, this is not the correct option for this. Trying to follow the suggestion in this answer, I produced the following code:
documentclassarticle
usepackagepgfplots
usetikzlibraryshapes.geometric,arrows,arrows.meta
pgfdeclarelayerbackground
pgfsetlayersbackground,main
begindocument
begintikzpicture
beginaxis[width=textwidth,
xmin=-0.5, xmax=6,
ymin=-0.5, ymax=4,
axis on top,
axis line style = thin,
axis lines=middle,
axis line style=-Stealth[length=2.5mm],
thick,
grid=major, grid style=dashed,gray!30]
beginpgfonlayermain
addplot[samples = 100] x^(1/2);
endpgfonlayer
endaxis
endtikzpicture
enddocument
But it doesn't work (grid is still in foreground). How to properly set the layers?
tikz-pgf pgfplots
add a comment |Â
up vote
3
down vote
favorite
In a plot with pgfplots I would like to draw, from background to foreground, in the following order:
- (background) grid;
- (intermediate layer) plot;
- (foreground) axis.
As specified in this answer,
Adding
axis on top
to the axis options means axis lines, ticks and
grids are printed on top of the stuff inside the environment.
So, this is not the correct option for this. Trying to follow the suggestion in this answer, I produced the following code:
documentclassarticle
usepackagepgfplots
usetikzlibraryshapes.geometric,arrows,arrows.meta
pgfdeclarelayerbackground
pgfsetlayersbackground,main
begindocument
begintikzpicture
beginaxis[width=textwidth,
xmin=-0.5, xmax=6,
ymin=-0.5, ymax=4,
axis on top,
axis line style = thin,
axis lines=middle,
axis line style=-Stealth[length=2.5mm],
thick,
grid=major, grid style=dashed,gray!30]
beginpgfonlayermain
addplot[samples = 100] x^(1/2);
endpgfonlayer
endaxis
endtikzpicture
enddocument
But it doesn't work (grid is still in foreground). How to properly set the layers?
tikz-pgf pgfplots
1
The easiest way is probably to useaxis on top
but draw the grid by hand, behind the plot.
â Henri Menke
19 mins ago
@HenriMenke As far as I understood, the fact that axis and grid go together, complicates the problem. Having several plots with different axis max and min values would make quite troublesome also to draw by hand the grid each time.
â BowPark
15 mins ago
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
In a plot with pgfplots I would like to draw, from background to foreground, in the following order:
- (background) grid;
- (intermediate layer) plot;
- (foreground) axis.
As specified in this answer,
Adding
axis on top
to the axis options means axis lines, ticks and
grids are printed on top of the stuff inside the environment.
So, this is not the correct option for this. Trying to follow the suggestion in this answer, I produced the following code:
documentclassarticle
usepackagepgfplots
usetikzlibraryshapes.geometric,arrows,arrows.meta
pgfdeclarelayerbackground
pgfsetlayersbackground,main
begindocument
begintikzpicture
beginaxis[width=textwidth,
xmin=-0.5, xmax=6,
ymin=-0.5, ymax=4,
axis on top,
axis line style = thin,
axis lines=middle,
axis line style=-Stealth[length=2.5mm],
thick,
grid=major, grid style=dashed,gray!30]
beginpgfonlayermain
addplot[samples = 100] x^(1/2);
endpgfonlayer
endaxis
endtikzpicture
enddocument
But it doesn't work (grid is still in foreground). How to properly set the layers?
tikz-pgf pgfplots
In a plot with pgfplots I would like to draw, from background to foreground, in the following order:
- (background) grid;
- (intermediate layer) plot;
- (foreground) axis.
As specified in this answer,
Adding
axis on top
to the axis options means axis lines, ticks and
grids are printed on top of the stuff inside the environment.
So, this is not the correct option for this. Trying to follow the suggestion in this answer, I produced the following code:
documentclassarticle
usepackagepgfplots
usetikzlibraryshapes.geometric,arrows,arrows.meta
pgfdeclarelayerbackground
pgfsetlayersbackground,main
begindocument
begintikzpicture
beginaxis[width=textwidth,
xmin=-0.5, xmax=6,
ymin=-0.5, ymax=4,
axis on top,
axis line style = thin,
axis lines=middle,
axis line style=-Stealth[length=2.5mm],
thick,
grid=major, grid style=dashed,gray!30]
beginpgfonlayermain
addplot[samples = 100] x^(1/2);
endpgfonlayer
endaxis
endtikzpicture
enddocument
But it doesn't work (grid is still in foreground). How to properly set the layers?
tikz-pgf pgfplots
tikz-pgf pgfplots
asked 4 hours ago
BowPark
45228
45228
1
The easiest way is probably to useaxis on top
but draw the grid by hand, behind the plot.
â Henri Menke
19 mins ago
@HenriMenke As far as I understood, the fact that axis and grid go together, complicates the problem. Having several plots with different axis max and min values would make quite troublesome also to draw by hand the grid each time.
â BowPark
15 mins ago
add a comment |Â
1
The easiest way is probably to useaxis on top
but draw the grid by hand, behind the plot.
â Henri Menke
19 mins ago
@HenriMenke As far as I understood, the fact that axis and grid go together, complicates the problem. Having several plots with different axis max and min values would make quite troublesome also to draw by hand the grid each time.
â BowPark
15 mins ago
1
1
The easiest way is probably to use
axis on top
but draw the grid by hand, behind the plot.â Henri Menke
19 mins ago
The easiest way is probably to use
axis on top
but draw the grid by hand, behind the plot.â Henri Menke
19 mins ago
@HenriMenke As far as I understood, the fact that axis and grid go together, complicates the problem. Having several plots with different axis max and min values would make quite troublesome also to draw by hand the grid each time.
â BowPark
15 mins ago
@HenriMenke As far as I understood, the fact that axis and grid go together, complicates the problem. Having several plots with different axis max and min values would make quite troublesome also to draw by hand the grid each time.
â BowPark
15 mins ago
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
This is discussed at length in section 4.27 of the pgfplots manual. All I did is to define a new layer set based on axis on top
in which I flip the order of axis grid
and main
.
documentclassarticle
usepackagepgfplots
usetikzlibraryshapes.geometric,arrows,arrows.meta
pgfplotsset
/pgfplots/layers/Bowpark/.define layer set=
axis background,axis grid,main,axis ticks,axis lines,axis tick labels,
axis descriptions,axis foreground
/pgfplots/layers/standard,
begindocument
begintikzpicture
beginaxis[/pgfplots/layers/Bowpark,
width=textwidth,
xmin=-0.5, xmax=6,
ymin=-0.5, ymax=4,
axis line style = thin,
axis lines=middle,
axis line style=-Stealth[length=2.5mm],
thick,
grid=major, grid style=dashed,gray!30]
addplot[samples = 100] x^(1/2);
endaxis
endtikzpicture
enddocument
add a comment |Â
up vote
1
down vote
From my code now the grid is in background using dotted
instead of dashed
.
documentclassarticle
usepackagepgfplots
usetikzlibraryshapes.geometric,arrows,arrows.meta
pgfdeclarelayerbackground
pgfsetlayersbackground,main
%for the grid
pgfplotssetmajor grid style=dotted,gray!30
begindocument
begintikzpicture
beginaxis[width=textwidth,
xmin=-0.5, xmax=6,
ymin=-0.5, ymax=4,
axis on top,
axis line style = thin,
axis lines=middle,
axis line style=-Stealth[length=2.5mm],
thick,
grid = major,
grid style=dashed, gray!30]
beginpgfonlayermain
addplot[samples = 100] x^(1/2);
endpgfonlayer
endaxis
endtikzpicture
enddocument
1
Grid must be below the graph (explicitly stated in the question)
â fontgeologist
25 mins ago
Before of a downvote, I think that an user colud wait.
â Sebastiano
23 mins ago
1
Why wait if the answer does not address the problem? Why not wait before answering to make sure to understand the problem?
â fontgeologist
22 mins ago
I'm using Papeeria and I have a light source was very bright and you could not see the image produced.
â Sebastiano
13 mins ago
NO! The dots are still above the graph. This is wrong! If you would dissect the resulting pdf you would notice this.
â fontgeologist
9 mins ago
 |Â
show 1 more comment
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
This is discussed at length in section 4.27 of the pgfplots manual. All I did is to define a new layer set based on axis on top
in which I flip the order of axis grid
and main
.
documentclassarticle
usepackagepgfplots
usetikzlibraryshapes.geometric,arrows,arrows.meta
pgfplotsset
/pgfplots/layers/Bowpark/.define layer set=
axis background,axis grid,main,axis ticks,axis lines,axis tick labels,
axis descriptions,axis foreground
/pgfplots/layers/standard,
begindocument
begintikzpicture
beginaxis[/pgfplots/layers/Bowpark,
width=textwidth,
xmin=-0.5, xmax=6,
ymin=-0.5, ymax=4,
axis line style = thin,
axis lines=middle,
axis line style=-Stealth[length=2.5mm],
thick,
grid=major, grid style=dashed,gray!30]
addplot[samples = 100] x^(1/2);
endaxis
endtikzpicture
enddocument
add a comment |Â
up vote
3
down vote
This is discussed at length in section 4.27 of the pgfplots manual. All I did is to define a new layer set based on axis on top
in which I flip the order of axis grid
and main
.
documentclassarticle
usepackagepgfplots
usetikzlibraryshapes.geometric,arrows,arrows.meta
pgfplotsset
/pgfplots/layers/Bowpark/.define layer set=
axis background,axis grid,main,axis ticks,axis lines,axis tick labels,
axis descriptions,axis foreground
/pgfplots/layers/standard,
begindocument
begintikzpicture
beginaxis[/pgfplots/layers/Bowpark,
width=textwidth,
xmin=-0.5, xmax=6,
ymin=-0.5, ymax=4,
axis line style = thin,
axis lines=middle,
axis line style=-Stealth[length=2.5mm],
thick,
grid=major, grid style=dashed,gray!30]
addplot[samples = 100] x^(1/2);
endaxis
endtikzpicture
enddocument
add a comment |Â
up vote
3
down vote
up vote
3
down vote
This is discussed at length in section 4.27 of the pgfplots manual. All I did is to define a new layer set based on axis on top
in which I flip the order of axis grid
and main
.
documentclassarticle
usepackagepgfplots
usetikzlibraryshapes.geometric,arrows,arrows.meta
pgfplotsset
/pgfplots/layers/Bowpark/.define layer set=
axis background,axis grid,main,axis ticks,axis lines,axis tick labels,
axis descriptions,axis foreground
/pgfplots/layers/standard,
begindocument
begintikzpicture
beginaxis[/pgfplots/layers/Bowpark,
width=textwidth,
xmin=-0.5, xmax=6,
ymin=-0.5, ymax=4,
axis line style = thin,
axis lines=middle,
axis line style=-Stealth[length=2.5mm],
thick,
grid=major, grid style=dashed,gray!30]
addplot[samples = 100] x^(1/2);
endaxis
endtikzpicture
enddocument
This is discussed at length in section 4.27 of the pgfplots manual. All I did is to define a new layer set based on axis on top
in which I flip the order of axis grid
and main
.
documentclassarticle
usepackagepgfplots
usetikzlibraryshapes.geometric,arrows,arrows.meta
pgfplotsset
/pgfplots/layers/Bowpark/.define layer set=
axis background,axis grid,main,axis ticks,axis lines,axis tick labels,
axis descriptions,axis foreground
/pgfplots/layers/standard,
begindocument
begintikzpicture
beginaxis[/pgfplots/layers/Bowpark,
width=textwidth,
xmin=-0.5, xmax=6,
ymin=-0.5, ymax=4,
axis line style = thin,
axis lines=middle,
axis line style=-Stealth[length=2.5mm],
thick,
grid=major, grid style=dashed,gray!30]
addplot[samples = 100] x^(1/2);
endaxis
endtikzpicture
enddocument
answered 11 mins ago
marmot
68.6k476148
68.6k476148
add a comment |Â
add a comment |Â
up vote
1
down vote
From my code now the grid is in background using dotted
instead of dashed
.
documentclassarticle
usepackagepgfplots
usetikzlibraryshapes.geometric,arrows,arrows.meta
pgfdeclarelayerbackground
pgfsetlayersbackground,main
%for the grid
pgfplotssetmajor grid style=dotted,gray!30
begindocument
begintikzpicture
beginaxis[width=textwidth,
xmin=-0.5, xmax=6,
ymin=-0.5, ymax=4,
axis on top,
axis line style = thin,
axis lines=middle,
axis line style=-Stealth[length=2.5mm],
thick,
grid = major,
grid style=dashed, gray!30]
beginpgfonlayermain
addplot[samples = 100] x^(1/2);
endpgfonlayer
endaxis
endtikzpicture
enddocument
1
Grid must be below the graph (explicitly stated in the question)
â fontgeologist
25 mins ago
Before of a downvote, I think that an user colud wait.
â Sebastiano
23 mins ago
1
Why wait if the answer does not address the problem? Why not wait before answering to make sure to understand the problem?
â fontgeologist
22 mins ago
I'm using Papeeria and I have a light source was very bright and you could not see the image produced.
â Sebastiano
13 mins ago
NO! The dots are still above the graph. This is wrong! If you would dissect the resulting pdf you would notice this.
â fontgeologist
9 mins ago
 |Â
show 1 more comment
up vote
1
down vote
From my code now the grid is in background using dotted
instead of dashed
.
documentclassarticle
usepackagepgfplots
usetikzlibraryshapes.geometric,arrows,arrows.meta
pgfdeclarelayerbackground
pgfsetlayersbackground,main
%for the grid
pgfplotssetmajor grid style=dotted,gray!30
begindocument
begintikzpicture
beginaxis[width=textwidth,
xmin=-0.5, xmax=6,
ymin=-0.5, ymax=4,
axis on top,
axis line style = thin,
axis lines=middle,
axis line style=-Stealth[length=2.5mm],
thick,
grid = major,
grid style=dashed, gray!30]
beginpgfonlayermain
addplot[samples = 100] x^(1/2);
endpgfonlayer
endaxis
endtikzpicture
enddocument
1
Grid must be below the graph (explicitly stated in the question)
â fontgeologist
25 mins ago
Before of a downvote, I think that an user colud wait.
â Sebastiano
23 mins ago
1
Why wait if the answer does not address the problem? Why not wait before answering to make sure to understand the problem?
â fontgeologist
22 mins ago
I'm using Papeeria and I have a light source was very bright and you could not see the image produced.
â Sebastiano
13 mins ago
NO! The dots are still above the graph. This is wrong! If you would dissect the resulting pdf you would notice this.
â fontgeologist
9 mins ago
 |Â
show 1 more comment
up vote
1
down vote
up vote
1
down vote
From my code now the grid is in background using dotted
instead of dashed
.
documentclassarticle
usepackagepgfplots
usetikzlibraryshapes.geometric,arrows,arrows.meta
pgfdeclarelayerbackground
pgfsetlayersbackground,main
%for the grid
pgfplotssetmajor grid style=dotted,gray!30
begindocument
begintikzpicture
beginaxis[width=textwidth,
xmin=-0.5, xmax=6,
ymin=-0.5, ymax=4,
axis on top,
axis line style = thin,
axis lines=middle,
axis line style=-Stealth[length=2.5mm],
thick,
grid = major,
grid style=dashed, gray!30]
beginpgfonlayermain
addplot[samples = 100] x^(1/2);
endpgfonlayer
endaxis
endtikzpicture
enddocument
From my code now the grid is in background using dotted
instead of dashed
.
documentclassarticle
usepackagepgfplots
usetikzlibraryshapes.geometric,arrows,arrows.meta
pgfdeclarelayerbackground
pgfsetlayersbackground,main
%for the grid
pgfplotssetmajor grid style=dotted,gray!30
begindocument
begintikzpicture
beginaxis[width=textwidth,
xmin=-0.5, xmax=6,
ymin=-0.5, ymax=4,
axis on top,
axis line style = thin,
axis lines=middle,
axis line style=-Stealth[length=2.5mm],
thick,
grid = major,
grid style=dashed, gray!30]
beginpgfonlayermain
addplot[samples = 100] x^(1/2);
endpgfonlayer
endaxis
endtikzpicture
enddocument
edited 15 mins ago
answered 32 mins ago
Sebastiano
7,85041654
7,85041654
1
Grid must be below the graph (explicitly stated in the question)
â fontgeologist
25 mins ago
Before of a downvote, I think that an user colud wait.
â Sebastiano
23 mins ago
1
Why wait if the answer does not address the problem? Why not wait before answering to make sure to understand the problem?
â fontgeologist
22 mins ago
I'm using Papeeria and I have a light source was very bright and you could not see the image produced.
â Sebastiano
13 mins ago
NO! The dots are still above the graph. This is wrong! If you would dissect the resulting pdf you would notice this.
â fontgeologist
9 mins ago
 |Â
show 1 more comment
1
Grid must be below the graph (explicitly stated in the question)
â fontgeologist
25 mins ago
Before of a downvote, I think that an user colud wait.
â Sebastiano
23 mins ago
1
Why wait if the answer does not address the problem? Why not wait before answering to make sure to understand the problem?
â fontgeologist
22 mins ago
I'm using Papeeria and I have a light source was very bright and you could not see the image produced.
â Sebastiano
13 mins ago
NO! The dots are still above the graph. This is wrong! If you would dissect the resulting pdf you would notice this.
â fontgeologist
9 mins ago
1
1
Grid must be below the graph (explicitly stated in the question)
â fontgeologist
25 mins ago
Grid must be below the graph (explicitly stated in the question)
â fontgeologist
25 mins ago
Before of a downvote, I think that an user colud wait.
â Sebastiano
23 mins ago
Before of a downvote, I think that an user colud wait.
â Sebastiano
23 mins ago
1
1
Why wait if the answer does not address the problem? Why not wait before answering to make sure to understand the problem?
â fontgeologist
22 mins ago
Why wait if the answer does not address the problem? Why not wait before answering to make sure to understand the problem?
â fontgeologist
22 mins ago
I'm using Papeeria and I have a light source was very bright and you could not see the image produced.
â Sebastiano
13 mins ago
I'm using Papeeria and I have a light source was very bright and you could not see the image produced.
â Sebastiano
13 mins ago
NO! The dots are still above the graph. This is wrong! If you would dissect the resulting pdf you would notice this.
â fontgeologist
9 mins ago
NO! The dots are still above the graph. This is wrong! If you would dissect the resulting pdf you would notice this.
â fontgeologist
9 mins ago
 |Â
show 1 more comment
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f456859%2fput-grid-below-plot-in-pgfplots%23new-answer', 'question_page');
);
Post as a guest
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
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
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
1
The easiest way is probably to use
axis on top
but draw the grid by hand, behind the plot.â Henri Menke
19 mins ago
@HenriMenke As far as I understood, the fact that axis and grid go together, complicates the problem. Having several plots with different axis max and min values would make quite troublesome also to draw by hand the grid each time.
â BowPark
15 mins ago