Adding legend entry for border of fill, from fillbetween
up vote
3
down vote
favorite
I've made a plot like the one below to show a distribution of values in the dependent variable versus the change of the independent variable.
documentclass[varwidth]{standalone}
usepackage{pgfplots}
usepackage{pgfplotstable}
usepgfplotslibrary{fillbetween}
usepackage{tikz}
pgfplotstableread{
x min q1 med q3 max
1 0 2 4 6 8
2 2 4 5 6 8
3 1 3 5 7 9
}data%
begin{document}
begin{tikzpicture}
begin{axis}[title=Example,
xlabel=x,
ylabel=y,
]
addplot[blue, dashed] table [x=x, y=min] {data};
addplot[blue, dotted, name path global=q1] table [x=x, y=q1] {data};
addplot[blue, solid] table [x=x, y=med] {data};
addplot[blue, dotted, name path global=q3] table [x=x, y=q3] {data};
addplot[blue, dashed] table [x=x, y=max] {data};
addplot[blue, fill opacity=0.3] fill between[of=q1 and q3];
end{axis}
end{tikzpicture}
end{document}
I'd like to have a legend like the following,
Is that possible? How?
Edit: adding my full solution
The solution below got most of what I was looking for, and with a few minor edits I was able to get it perfect. (Well, the image below isn't quite perfect--just realized I switched Q1 and Q3.)
I increased the size of the custom legend entry from 0.1cm to 0.4cm,
pgfplotsset{custom legend/.style={%
/pgfplots/legend image code/.code={%
path[##1] (0cm,-.4cm) rectangle (0.6cm,0.4cm);
draw[dotted] (0cm,-0.4cm) -- (0.6cm,-0.4cm)
(0cm,0.4cm) -- (0.6cm,0.4cm);
draw[blue] (0cm,0cm) -- (0.6cm,0cm);
}}}
And made the corresponding legend entry three lines,
begin{axis}[title=Example,
xlabel=x,
ylabel=y,
legend style={cells={align=left}},
]
addlegendimage{blue,dashed}
addlegendentry[font=sffamily]{Maximum}
addlegendimage{custom legend,draw=none,fill=blue,fill opacity=0.3}
addlegendentry[xshift=-2mm,font=sffamily]{Q1 \ Median \ Q3}
addlegendimage{blue,dashed}
addlegendentry[xshift=-0.2mm,font=sffamily]{Minimum}
...
pgfplots legend fillbetween
add a comment |
up vote
3
down vote
favorite
I've made a plot like the one below to show a distribution of values in the dependent variable versus the change of the independent variable.
documentclass[varwidth]{standalone}
usepackage{pgfplots}
usepackage{pgfplotstable}
usepgfplotslibrary{fillbetween}
usepackage{tikz}
pgfplotstableread{
x min q1 med q3 max
1 0 2 4 6 8
2 2 4 5 6 8
3 1 3 5 7 9
}data%
begin{document}
begin{tikzpicture}
begin{axis}[title=Example,
xlabel=x,
ylabel=y,
]
addplot[blue, dashed] table [x=x, y=min] {data};
addplot[blue, dotted, name path global=q1] table [x=x, y=q1] {data};
addplot[blue, solid] table [x=x, y=med] {data};
addplot[blue, dotted, name path global=q3] table [x=x, y=q3] {data};
addplot[blue, dashed] table [x=x, y=max] {data};
addplot[blue, fill opacity=0.3] fill between[of=q1 and q3];
end{axis}
end{tikzpicture}
end{document}
I'd like to have a legend like the following,
Is that possible? How?
Edit: adding my full solution
The solution below got most of what I was looking for, and with a few minor edits I was able to get it perfect. (Well, the image below isn't quite perfect--just realized I switched Q1 and Q3.)
I increased the size of the custom legend entry from 0.1cm to 0.4cm,
pgfplotsset{custom legend/.style={%
/pgfplots/legend image code/.code={%
path[##1] (0cm,-.4cm) rectangle (0.6cm,0.4cm);
draw[dotted] (0cm,-0.4cm) -- (0.6cm,-0.4cm)
(0cm,0.4cm) -- (0.6cm,0.4cm);
draw[blue] (0cm,0cm) -- (0.6cm,0cm);
}}}
And made the corresponding legend entry three lines,
begin{axis}[title=Example,
xlabel=x,
ylabel=y,
legend style={cells={align=left}},
]
addlegendimage{blue,dashed}
addlegendentry[font=sffamily]{Maximum}
addlegendimage{custom legend,draw=none,fill=blue,fill opacity=0.3}
addlegendentry[xshift=-2mm,font=sffamily]{Q1 \ Median \ Q3}
addlegendimage{blue,dashed}
addlegendentry[xshift=-0.2mm,font=sffamily]{Minimum}
...
pgfplots legend fillbetween
add a comment |
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I've made a plot like the one below to show a distribution of values in the dependent variable versus the change of the independent variable.
documentclass[varwidth]{standalone}
usepackage{pgfplots}
usepackage{pgfplotstable}
usepgfplotslibrary{fillbetween}
usepackage{tikz}
pgfplotstableread{
x min q1 med q3 max
1 0 2 4 6 8
2 2 4 5 6 8
3 1 3 5 7 9
}data%
begin{document}
begin{tikzpicture}
begin{axis}[title=Example,
xlabel=x,
ylabel=y,
]
addplot[blue, dashed] table [x=x, y=min] {data};
addplot[blue, dotted, name path global=q1] table [x=x, y=q1] {data};
addplot[blue, solid] table [x=x, y=med] {data};
addplot[blue, dotted, name path global=q3] table [x=x, y=q3] {data};
addplot[blue, dashed] table [x=x, y=max] {data};
addplot[blue, fill opacity=0.3] fill between[of=q1 and q3];
end{axis}
end{tikzpicture}
end{document}
I'd like to have a legend like the following,
Is that possible? How?
Edit: adding my full solution
The solution below got most of what I was looking for, and with a few minor edits I was able to get it perfect. (Well, the image below isn't quite perfect--just realized I switched Q1 and Q3.)
I increased the size of the custom legend entry from 0.1cm to 0.4cm,
pgfplotsset{custom legend/.style={%
/pgfplots/legend image code/.code={%
path[##1] (0cm,-.4cm) rectangle (0.6cm,0.4cm);
draw[dotted] (0cm,-0.4cm) -- (0.6cm,-0.4cm)
(0cm,0.4cm) -- (0.6cm,0.4cm);
draw[blue] (0cm,0cm) -- (0.6cm,0cm);
}}}
And made the corresponding legend entry three lines,
begin{axis}[title=Example,
xlabel=x,
ylabel=y,
legend style={cells={align=left}},
]
addlegendimage{blue,dashed}
addlegendentry[font=sffamily]{Maximum}
addlegendimage{custom legend,draw=none,fill=blue,fill opacity=0.3}
addlegendentry[xshift=-2mm,font=sffamily]{Q1 \ Median \ Q3}
addlegendimage{blue,dashed}
addlegendentry[xshift=-0.2mm,font=sffamily]{Minimum}
...
pgfplots legend fillbetween
I've made a plot like the one below to show a distribution of values in the dependent variable versus the change of the independent variable.
documentclass[varwidth]{standalone}
usepackage{pgfplots}
usepackage{pgfplotstable}
usepgfplotslibrary{fillbetween}
usepackage{tikz}
pgfplotstableread{
x min q1 med q3 max
1 0 2 4 6 8
2 2 4 5 6 8
3 1 3 5 7 9
}data%
begin{document}
begin{tikzpicture}
begin{axis}[title=Example,
xlabel=x,
ylabel=y,
]
addplot[blue, dashed] table [x=x, y=min] {data};
addplot[blue, dotted, name path global=q1] table [x=x, y=q1] {data};
addplot[blue, solid] table [x=x, y=med] {data};
addplot[blue, dotted, name path global=q3] table [x=x, y=q3] {data};
addplot[blue, dashed] table [x=x, y=max] {data};
addplot[blue, fill opacity=0.3] fill between[of=q1 and q3];
end{axis}
end{tikzpicture}
end{document}
I'd like to have a legend like the following,
Is that possible? How?
Edit: adding my full solution
The solution below got most of what I was looking for, and with a few minor edits I was able to get it perfect. (Well, the image below isn't quite perfect--just realized I switched Q1 and Q3.)
I increased the size of the custom legend entry from 0.1cm to 0.4cm,
pgfplotsset{custom legend/.style={%
/pgfplots/legend image code/.code={%
path[##1] (0cm,-.4cm) rectangle (0.6cm,0.4cm);
draw[dotted] (0cm,-0.4cm) -- (0.6cm,-0.4cm)
(0cm,0.4cm) -- (0.6cm,0.4cm);
draw[blue] (0cm,0cm) -- (0.6cm,0cm);
}}}
And made the corresponding legend entry three lines,
begin{axis}[title=Example,
xlabel=x,
ylabel=y,
legend style={cells={align=left}},
]
addlegendimage{blue,dashed}
addlegendentry[font=sffamily]{Maximum}
addlegendimage{custom legend,draw=none,fill=blue,fill opacity=0.3}
addlegendentry[xshift=-2mm,font=sffamily]{Q1 \ Median \ Q3}
addlegendimage{blue,dashed}
addlegendentry[xshift=-0.2mm,font=sffamily]{Minimum}
...
pgfplots legend fillbetween
pgfplots legend fillbetween
edited 11 hours ago
asked 22 hours ago
john_stech
253
253
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
Here is a proposal. I looked uparea legend
in pgfplots.code.tex
and used it as a basis for custom legend
, which comes already close to what you want, I think, and can be further customized. (I am pretty sure I have seen an answer using similar tricks but even after some long search I couldn't find it. I am definitely not claiming that I am the first one doing these tricks.) Anyway, the result of a quick customization (after a long search without hits) is
documentclass[varwidth]{standalone}
usepackage{pgfplots}
usepackage{pgfplotstable}
usepgfplotslibrary{fillbetween}
usepackage{tikz}
pgfplotstableread{
x min q1 med q3 max
1 0 2 4 6 8
2 2 4 5 6 8
3 1 3 5 7 9
}data%
pgfplotsset{custom legend/.style={%
/pgfplots/legend image code/.code={%
path[##1] (0cm,-0.1cm) rectangle (0.6cm,0.1cm);
draw[dotted] (0cm,-0.1cm) -- (0.6cm,-0.1cm)
(0cm,0.1cm) -- (0.6cm,0.1cm);
draw[blue] (0cm,0cm) -- (0.6cm,0cm);
}}}
begin{document}
begin{tikzpicture}
begin{axis}[title=Example,
xlabel=x,
ylabel=y,
]
addlegendimage{blue,dashed}
addlegendentry[font=sffamily]{Maximum}
addlegendimage{custom legend,draw=none,fill=blue,fill opacity=0.3}
addlegendentry[xshift=-2mm,font=sffamily]{Median}
addlegendimage{blue,dashed}
addlegendentry[xshift=-0.2mm,font=sffamily]{Minimum}
addplot[blue, dashed] table [x=x, y=min] {data};
addplot[blue, dotted, name path global=q1] table [x=x, y=q1] {data};
addplot[blue, solid] table [x=x, y=med] {data};
addplot[blue, dotted, name path global=q3] table [x=x, y=q3] {data};
addplot[blue, dashed] table [x=x, y=max] {data};
addplot[blue, fill opacity=0.3] fill between[of=q1 and q3];
end{axis}
end{tikzpicture}
end{document}
After some amount of hibernation I will be happy to assist you in further customization, if needed.
1
Awesome! This got me on the right path, and with a few small changes I got exactly what I wanted. I increased the size of the custom image in the y dimension, and made the corresponding text a three-line entry (as described in this question).
– john_stech
13 hours ago
@john_stech Thanks! (I was too tired last night to do the tuning, and I am really glad you got what I wanted. I'm wondering you want to add the information what you did to your question, other users might find that useful.)
– marmot
11 hours ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Here is a proposal. I looked uparea legend
in pgfplots.code.tex
and used it as a basis for custom legend
, which comes already close to what you want, I think, and can be further customized. (I am pretty sure I have seen an answer using similar tricks but even after some long search I couldn't find it. I am definitely not claiming that I am the first one doing these tricks.) Anyway, the result of a quick customization (after a long search without hits) is
documentclass[varwidth]{standalone}
usepackage{pgfplots}
usepackage{pgfplotstable}
usepgfplotslibrary{fillbetween}
usepackage{tikz}
pgfplotstableread{
x min q1 med q3 max
1 0 2 4 6 8
2 2 4 5 6 8
3 1 3 5 7 9
}data%
pgfplotsset{custom legend/.style={%
/pgfplots/legend image code/.code={%
path[##1] (0cm,-0.1cm) rectangle (0.6cm,0.1cm);
draw[dotted] (0cm,-0.1cm) -- (0.6cm,-0.1cm)
(0cm,0.1cm) -- (0.6cm,0.1cm);
draw[blue] (0cm,0cm) -- (0.6cm,0cm);
}}}
begin{document}
begin{tikzpicture}
begin{axis}[title=Example,
xlabel=x,
ylabel=y,
]
addlegendimage{blue,dashed}
addlegendentry[font=sffamily]{Maximum}
addlegendimage{custom legend,draw=none,fill=blue,fill opacity=0.3}
addlegendentry[xshift=-2mm,font=sffamily]{Median}
addlegendimage{blue,dashed}
addlegendentry[xshift=-0.2mm,font=sffamily]{Minimum}
addplot[blue, dashed] table [x=x, y=min] {data};
addplot[blue, dotted, name path global=q1] table [x=x, y=q1] {data};
addplot[blue, solid] table [x=x, y=med] {data};
addplot[blue, dotted, name path global=q3] table [x=x, y=q3] {data};
addplot[blue, dashed] table [x=x, y=max] {data};
addplot[blue, fill opacity=0.3] fill between[of=q1 and q3];
end{axis}
end{tikzpicture}
end{document}
After some amount of hibernation I will be happy to assist you in further customization, if needed.
1
Awesome! This got me on the right path, and with a few small changes I got exactly what I wanted. I increased the size of the custom image in the y dimension, and made the corresponding text a three-line entry (as described in this question).
– john_stech
13 hours ago
@john_stech Thanks! (I was too tired last night to do the tuning, and I am really glad you got what I wanted. I'm wondering you want to add the information what you did to your question, other users might find that useful.)
– marmot
11 hours ago
add a comment |
up vote
2
down vote
accepted
Here is a proposal. I looked uparea legend
in pgfplots.code.tex
and used it as a basis for custom legend
, which comes already close to what you want, I think, and can be further customized. (I am pretty sure I have seen an answer using similar tricks but even after some long search I couldn't find it. I am definitely not claiming that I am the first one doing these tricks.) Anyway, the result of a quick customization (after a long search without hits) is
documentclass[varwidth]{standalone}
usepackage{pgfplots}
usepackage{pgfplotstable}
usepgfplotslibrary{fillbetween}
usepackage{tikz}
pgfplotstableread{
x min q1 med q3 max
1 0 2 4 6 8
2 2 4 5 6 8
3 1 3 5 7 9
}data%
pgfplotsset{custom legend/.style={%
/pgfplots/legend image code/.code={%
path[##1] (0cm,-0.1cm) rectangle (0.6cm,0.1cm);
draw[dotted] (0cm,-0.1cm) -- (0.6cm,-0.1cm)
(0cm,0.1cm) -- (0.6cm,0.1cm);
draw[blue] (0cm,0cm) -- (0.6cm,0cm);
}}}
begin{document}
begin{tikzpicture}
begin{axis}[title=Example,
xlabel=x,
ylabel=y,
]
addlegendimage{blue,dashed}
addlegendentry[font=sffamily]{Maximum}
addlegendimage{custom legend,draw=none,fill=blue,fill opacity=0.3}
addlegendentry[xshift=-2mm,font=sffamily]{Median}
addlegendimage{blue,dashed}
addlegendentry[xshift=-0.2mm,font=sffamily]{Minimum}
addplot[blue, dashed] table [x=x, y=min] {data};
addplot[blue, dotted, name path global=q1] table [x=x, y=q1] {data};
addplot[blue, solid] table [x=x, y=med] {data};
addplot[blue, dotted, name path global=q3] table [x=x, y=q3] {data};
addplot[blue, dashed] table [x=x, y=max] {data};
addplot[blue, fill opacity=0.3] fill between[of=q1 and q3];
end{axis}
end{tikzpicture}
end{document}
After some amount of hibernation I will be happy to assist you in further customization, if needed.
1
Awesome! This got me on the right path, and with a few small changes I got exactly what I wanted. I increased the size of the custom image in the y dimension, and made the corresponding text a three-line entry (as described in this question).
– john_stech
13 hours ago
@john_stech Thanks! (I was too tired last night to do the tuning, and I am really glad you got what I wanted. I'm wondering you want to add the information what you did to your question, other users might find that useful.)
– marmot
11 hours ago
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Here is a proposal. I looked uparea legend
in pgfplots.code.tex
and used it as a basis for custom legend
, which comes already close to what you want, I think, and can be further customized. (I am pretty sure I have seen an answer using similar tricks but even after some long search I couldn't find it. I am definitely not claiming that I am the first one doing these tricks.) Anyway, the result of a quick customization (after a long search without hits) is
documentclass[varwidth]{standalone}
usepackage{pgfplots}
usepackage{pgfplotstable}
usepgfplotslibrary{fillbetween}
usepackage{tikz}
pgfplotstableread{
x min q1 med q3 max
1 0 2 4 6 8
2 2 4 5 6 8
3 1 3 5 7 9
}data%
pgfplotsset{custom legend/.style={%
/pgfplots/legend image code/.code={%
path[##1] (0cm,-0.1cm) rectangle (0.6cm,0.1cm);
draw[dotted] (0cm,-0.1cm) -- (0.6cm,-0.1cm)
(0cm,0.1cm) -- (0.6cm,0.1cm);
draw[blue] (0cm,0cm) -- (0.6cm,0cm);
}}}
begin{document}
begin{tikzpicture}
begin{axis}[title=Example,
xlabel=x,
ylabel=y,
]
addlegendimage{blue,dashed}
addlegendentry[font=sffamily]{Maximum}
addlegendimage{custom legend,draw=none,fill=blue,fill opacity=0.3}
addlegendentry[xshift=-2mm,font=sffamily]{Median}
addlegendimage{blue,dashed}
addlegendentry[xshift=-0.2mm,font=sffamily]{Minimum}
addplot[blue, dashed] table [x=x, y=min] {data};
addplot[blue, dotted, name path global=q1] table [x=x, y=q1] {data};
addplot[blue, solid] table [x=x, y=med] {data};
addplot[blue, dotted, name path global=q3] table [x=x, y=q3] {data};
addplot[blue, dashed] table [x=x, y=max] {data};
addplot[blue, fill opacity=0.3] fill between[of=q1 and q3];
end{axis}
end{tikzpicture}
end{document}
After some amount of hibernation I will be happy to assist you in further customization, if needed.
Here is a proposal. I looked uparea legend
in pgfplots.code.tex
and used it as a basis for custom legend
, which comes already close to what you want, I think, and can be further customized. (I am pretty sure I have seen an answer using similar tricks but even after some long search I couldn't find it. I am definitely not claiming that I am the first one doing these tricks.) Anyway, the result of a quick customization (after a long search without hits) is
documentclass[varwidth]{standalone}
usepackage{pgfplots}
usepackage{pgfplotstable}
usepgfplotslibrary{fillbetween}
usepackage{tikz}
pgfplotstableread{
x min q1 med q3 max
1 0 2 4 6 8
2 2 4 5 6 8
3 1 3 5 7 9
}data%
pgfplotsset{custom legend/.style={%
/pgfplots/legend image code/.code={%
path[##1] (0cm,-0.1cm) rectangle (0.6cm,0.1cm);
draw[dotted] (0cm,-0.1cm) -- (0.6cm,-0.1cm)
(0cm,0.1cm) -- (0.6cm,0.1cm);
draw[blue] (0cm,0cm) -- (0.6cm,0cm);
}}}
begin{document}
begin{tikzpicture}
begin{axis}[title=Example,
xlabel=x,
ylabel=y,
]
addlegendimage{blue,dashed}
addlegendentry[font=sffamily]{Maximum}
addlegendimage{custom legend,draw=none,fill=blue,fill opacity=0.3}
addlegendentry[xshift=-2mm,font=sffamily]{Median}
addlegendimage{blue,dashed}
addlegendentry[xshift=-0.2mm,font=sffamily]{Minimum}
addplot[blue, dashed] table [x=x, y=min] {data};
addplot[blue, dotted, name path global=q1] table [x=x, y=q1] {data};
addplot[blue, solid] table [x=x, y=med] {data};
addplot[blue, dotted, name path global=q3] table [x=x, y=q3] {data};
addplot[blue, dashed] table [x=x, y=max] {data};
addplot[blue, fill opacity=0.3] fill between[of=q1 and q3];
end{axis}
end{tikzpicture}
end{document}
After some amount of hibernation I will be happy to assist you in further customization, if needed.
answered 18 hours ago
marmot
78k487166
78k487166
1
Awesome! This got me on the right path, and with a few small changes I got exactly what I wanted. I increased the size of the custom image in the y dimension, and made the corresponding text a three-line entry (as described in this question).
– john_stech
13 hours ago
@john_stech Thanks! (I was too tired last night to do the tuning, and I am really glad you got what I wanted. I'm wondering you want to add the information what you did to your question, other users might find that useful.)
– marmot
11 hours ago
add a comment |
1
Awesome! This got me on the right path, and with a few small changes I got exactly what I wanted. I increased the size of the custom image in the y dimension, and made the corresponding text a three-line entry (as described in this question).
– john_stech
13 hours ago
@john_stech Thanks! (I was too tired last night to do the tuning, and I am really glad you got what I wanted. I'm wondering you want to add the information what you did to your question, other users might find that useful.)
– marmot
11 hours ago
1
1
Awesome! This got me on the right path, and with a few small changes I got exactly what I wanted. I increased the size of the custom image in the y dimension, and made the corresponding text a three-line entry (as described in this question).
– john_stech
13 hours ago
Awesome! This got me on the right path, and with a few small changes I got exactly what I wanted. I increased the size of the custom image in the y dimension, and made the corresponding text a three-line entry (as described in this question).
– john_stech
13 hours ago
@john_stech Thanks! (I was too tired last night to do the tuning, and I am really glad you got what I wanted. I'm wondering you want to add the information what you did to your question, other users might find that useful.)
– marmot
11 hours ago
@john_stech Thanks! (I was too tired last night to do the tuning, and I am really glad you got what I wanted. I'm wondering you want to add the information what you did to your question, other users might find that useful.)
– marmot
11 hours ago
add a 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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f461654%2fadding-legend-entry-for-border-of-fill-from-fillbetween%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