Is it possible to add the coloring range as legend?
$begingroup$
recently i've generated a 3d plot, where I colored the points by the distance from the center.
My question is, that is it possible to add the values associated with the colors as a legend?
An example code is the following:
ClearAll["Global`*"]
pointsChar = {{0.`, 0.`, 41.63`}, {8.50479382206883`, 0.`,
31.74032265185878`}, {14.975`, 0.`,
25.937460843343935`}, {19.69999492385721`, 0.`,
19.69999492385721`}, {23.053596248741755`, 0.`,
13.31`}, {25.12373074177866`, 0.`, 6.731883363116563`}, {26.16`,
0.`, 0.`}, {26.205567667222418`,
0.`, -7.0217606936313866`}, {24.595121467478055`,
0.`, -14.2`}, {21.630396436496486`,
0.`, -21.630396436496486`}, {16.62`,
0.`, -28.786684421794742`}, {10.396761041768258`,
0.`, -38.80124044203187`}}
ListPointPlot3D[pointsChar,
ColorFunction -> Function[{x, y, z}, Hue[Sqrt[x^2 + y^2 + z^2]]],
Filling -> Axis, BoxRatios -> {1, 1, 1},
PlotStyle -> PointSize[Large]]
plotting
$endgroup$
add a comment |
$begingroup$
recently i've generated a 3d plot, where I colored the points by the distance from the center.
My question is, that is it possible to add the values associated with the colors as a legend?
An example code is the following:
ClearAll["Global`*"]
pointsChar = {{0.`, 0.`, 41.63`}, {8.50479382206883`, 0.`,
31.74032265185878`}, {14.975`, 0.`,
25.937460843343935`}, {19.69999492385721`, 0.`,
19.69999492385721`}, {23.053596248741755`, 0.`,
13.31`}, {25.12373074177866`, 0.`, 6.731883363116563`}, {26.16`,
0.`, 0.`}, {26.205567667222418`,
0.`, -7.0217606936313866`}, {24.595121467478055`,
0.`, -14.2`}, {21.630396436496486`,
0.`, -21.630396436496486`}, {16.62`,
0.`, -28.786684421794742`}, {10.396761041768258`,
0.`, -38.80124044203187`}}
ListPointPlot3D[pointsChar,
ColorFunction -> Function[{x, y, z}, Hue[Sqrt[x^2 + y^2 + z^2]]],
Filling -> Axis, BoxRatios -> {1, 1, 1},
PlotStyle -> PointSize[Large]]
plotting
$endgroup$
2
$begingroup$
You can generate your legend usingBarLegend[{Hue,MinMax[EuclideanDistance[{0,0,0},#]&/@pointsChar]}]
.
$endgroup$
– N.J.Evans
Nov 16 '18 at 17:25
$begingroup$
Legended[ YYYYY , XXXX ] where YYYY your plot function as is and XXXX the legend code from @N.J. Evans, separated by a comma. I was happening to be working on the same problem but I could not match the colours with the legend. Maybe a complete answer can be posted by the first commentator...?
$endgroup$
– Titus
Nov 16 '18 at 17:52
add a comment |
$begingroup$
recently i've generated a 3d plot, where I colored the points by the distance from the center.
My question is, that is it possible to add the values associated with the colors as a legend?
An example code is the following:
ClearAll["Global`*"]
pointsChar = {{0.`, 0.`, 41.63`}, {8.50479382206883`, 0.`,
31.74032265185878`}, {14.975`, 0.`,
25.937460843343935`}, {19.69999492385721`, 0.`,
19.69999492385721`}, {23.053596248741755`, 0.`,
13.31`}, {25.12373074177866`, 0.`, 6.731883363116563`}, {26.16`,
0.`, 0.`}, {26.205567667222418`,
0.`, -7.0217606936313866`}, {24.595121467478055`,
0.`, -14.2`}, {21.630396436496486`,
0.`, -21.630396436496486`}, {16.62`,
0.`, -28.786684421794742`}, {10.396761041768258`,
0.`, -38.80124044203187`}}
ListPointPlot3D[pointsChar,
ColorFunction -> Function[{x, y, z}, Hue[Sqrt[x^2 + y^2 + z^2]]],
Filling -> Axis, BoxRatios -> {1, 1, 1},
PlotStyle -> PointSize[Large]]
plotting
$endgroup$
recently i've generated a 3d plot, where I colored the points by the distance from the center.
My question is, that is it possible to add the values associated with the colors as a legend?
An example code is the following:
ClearAll["Global`*"]
pointsChar = {{0.`, 0.`, 41.63`}, {8.50479382206883`, 0.`,
31.74032265185878`}, {14.975`, 0.`,
25.937460843343935`}, {19.69999492385721`, 0.`,
19.69999492385721`}, {23.053596248741755`, 0.`,
13.31`}, {25.12373074177866`, 0.`, 6.731883363116563`}, {26.16`,
0.`, 0.`}, {26.205567667222418`,
0.`, -7.0217606936313866`}, {24.595121467478055`,
0.`, -14.2`}, {21.630396436496486`,
0.`, -21.630396436496486`}, {16.62`,
0.`, -28.786684421794742`}, {10.396761041768258`,
0.`, -38.80124044203187`}}
ListPointPlot3D[pointsChar,
ColorFunction -> Function[{x, y, z}, Hue[Sqrt[x^2 + y^2 + z^2]]],
Filling -> Axis, BoxRatios -> {1, 1, 1},
PlotStyle -> PointSize[Large]]
plotting
plotting
asked Nov 16 '18 at 17:14
G.DavidG.David
715
715
2
$begingroup$
You can generate your legend usingBarLegend[{Hue,MinMax[EuclideanDistance[{0,0,0},#]&/@pointsChar]}]
.
$endgroup$
– N.J.Evans
Nov 16 '18 at 17:25
$begingroup$
Legended[ YYYYY , XXXX ] where YYYY your plot function as is and XXXX the legend code from @N.J. Evans, separated by a comma. I was happening to be working on the same problem but I could not match the colours with the legend. Maybe a complete answer can be posted by the first commentator...?
$endgroup$
– Titus
Nov 16 '18 at 17:52
add a comment |
2
$begingroup$
You can generate your legend usingBarLegend[{Hue,MinMax[EuclideanDistance[{0,0,0},#]&/@pointsChar]}]
.
$endgroup$
– N.J.Evans
Nov 16 '18 at 17:25
$begingroup$
Legended[ YYYYY , XXXX ] where YYYY your plot function as is and XXXX the legend code from @N.J. Evans, separated by a comma. I was happening to be working on the same problem but I could not match the colours with the legend. Maybe a complete answer can be posted by the first commentator...?
$endgroup$
– Titus
Nov 16 '18 at 17:52
2
2
$begingroup$
You can generate your legend using
BarLegend[{Hue,MinMax[EuclideanDistance[{0,0,0},#]&/@pointsChar]}]
.$endgroup$
– N.J.Evans
Nov 16 '18 at 17:25
$begingroup$
You can generate your legend using
BarLegend[{Hue,MinMax[EuclideanDistance[{0,0,0},#]&/@pointsChar]}]
.$endgroup$
– N.J.Evans
Nov 16 '18 at 17:25
$begingroup$
Legended[ YYYYY , XXXX ] where YYYY your plot function as is and XXXX the legend code from @N.J. Evans, separated by a comma. I was happening to be working on the same problem but I could not match the colours with the legend. Maybe a complete answer can be posted by the first commentator...?
$endgroup$
– Titus
Nov 16 '18 at 17:52
$begingroup$
Legended[ YYYYY , XXXX ] where YYYY your plot function as is and XXXX the legend code from @N.J. Evans, separated by a comma. I was happening to be working on the same problem but I could not match the colours with the legend. Maybe a complete answer can be posted by the first commentator...?
$endgroup$
– Titus
Nov 16 '18 at 17:52
add a comment |
2 Answers
2
active
oldest
votes
$begingroup$
ClearAll["Global`*"]
pointsChar = {{0.`, 0.`, 41.63`}, {8.50479382206883`, 0.`,
31.74032265185878`}, {14.975`, 0.`,
25.937460843343935`}, {19.69999492385721`, 0.`,
19.69999492385721`}, {23.053596248741755`, 0.`,
13.31`}, {25.12373074177866`, 0.`, 6.731883363116563`}, {26.16`, 0.`,
0.`}, {26.205567667222418`,
0.`, -7.0217606936313866`}, {24.595121467478055`,
0.`, -14.2`}, {21.630396436496486`, 0.`, -21.630396436496486`}, {16.62`,
0.`, -28.786684421794742`}, {10.396761041768258`,
0.`, -38.80124044203187`}};
{minDist, maxDist} = MinMax[EuclideanDistance[{0, 0, 0}, #] & /@ pointsChar];
Since colors given by Hue
are the same for min and max values, an alternative color function may be desired. Further, the EuclideanDistance
is given in the Tooltip
.
Manipulate[
Legended[
ListPointPlot3D[
Tooltip[#, EuclideanDistance[{0, 0, 0}, #]] & /@
pointsChar,
ColorFunction ->
Function[{x, y, z},
If[cf === Hue, Hue, ColorData[cf]][
Rescale[Sqrt[x^2 + y^2 + z^2], {minDist, maxDist}]]],
ColorFunctionScaling -> False,
Filling -> Axis,
BoxRatios -> {1, 1, 1},
PlotStyle -> PointSize[Large]],
BarLegend[{If[cf === Hue, Hue,
ColorData[cf][Rescale[#, {minDist, maxDist}]] &], {minDist, maxDist}}]],
{{cf, Hue, "ColorFunction"}, {Hue, "Rainbow", "TemperatureMap"}}]
$endgroup$
add a comment |
$begingroup$
You can extract the Point
primitives and their styles from ListPointPlot3D
output and use them to construct a PointLegend
:
lpp = ListPointPlot3D[pointsChar,
ColorFunction -> Function[{x, y, z}, Hue[Sqrt[x^2 + y^2 + z^2]]],
Filling -> Axis, BoxRatios -> {1, 1, 1},
PlotStyle -> PointSize[Large]];
legend = PointLegend[## & @@ Transpose[Cases[lpp, {a_, Point[b_]} :> {a, b}, ∞]],
LegendMarkerSize -> 20];
Legended[lpp, legend]
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "387"
};
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%2fmathematica.stackexchange.com%2fquestions%2f186133%2fis-it-possible-to-add-the-coloring-range-as-legend%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
ClearAll["Global`*"]
pointsChar = {{0.`, 0.`, 41.63`}, {8.50479382206883`, 0.`,
31.74032265185878`}, {14.975`, 0.`,
25.937460843343935`}, {19.69999492385721`, 0.`,
19.69999492385721`}, {23.053596248741755`, 0.`,
13.31`}, {25.12373074177866`, 0.`, 6.731883363116563`}, {26.16`, 0.`,
0.`}, {26.205567667222418`,
0.`, -7.0217606936313866`}, {24.595121467478055`,
0.`, -14.2`}, {21.630396436496486`, 0.`, -21.630396436496486`}, {16.62`,
0.`, -28.786684421794742`}, {10.396761041768258`,
0.`, -38.80124044203187`}};
{minDist, maxDist} = MinMax[EuclideanDistance[{0, 0, 0}, #] & /@ pointsChar];
Since colors given by Hue
are the same for min and max values, an alternative color function may be desired. Further, the EuclideanDistance
is given in the Tooltip
.
Manipulate[
Legended[
ListPointPlot3D[
Tooltip[#, EuclideanDistance[{0, 0, 0}, #]] & /@
pointsChar,
ColorFunction ->
Function[{x, y, z},
If[cf === Hue, Hue, ColorData[cf]][
Rescale[Sqrt[x^2 + y^2 + z^2], {minDist, maxDist}]]],
ColorFunctionScaling -> False,
Filling -> Axis,
BoxRatios -> {1, 1, 1},
PlotStyle -> PointSize[Large]],
BarLegend[{If[cf === Hue, Hue,
ColorData[cf][Rescale[#, {minDist, maxDist}]] &], {minDist, maxDist}}]],
{{cf, Hue, "ColorFunction"}, {Hue, "Rainbow", "TemperatureMap"}}]
$endgroup$
add a comment |
$begingroup$
ClearAll["Global`*"]
pointsChar = {{0.`, 0.`, 41.63`}, {8.50479382206883`, 0.`,
31.74032265185878`}, {14.975`, 0.`,
25.937460843343935`}, {19.69999492385721`, 0.`,
19.69999492385721`}, {23.053596248741755`, 0.`,
13.31`}, {25.12373074177866`, 0.`, 6.731883363116563`}, {26.16`, 0.`,
0.`}, {26.205567667222418`,
0.`, -7.0217606936313866`}, {24.595121467478055`,
0.`, -14.2`}, {21.630396436496486`, 0.`, -21.630396436496486`}, {16.62`,
0.`, -28.786684421794742`}, {10.396761041768258`,
0.`, -38.80124044203187`}};
{minDist, maxDist} = MinMax[EuclideanDistance[{0, 0, 0}, #] & /@ pointsChar];
Since colors given by Hue
are the same for min and max values, an alternative color function may be desired. Further, the EuclideanDistance
is given in the Tooltip
.
Manipulate[
Legended[
ListPointPlot3D[
Tooltip[#, EuclideanDistance[{0, 0, 0}, #]] & /@
pointsChar,
ColorFunction ->
Function[{x, y, z},
If[cf === Hue, Hue, ColorData[cf]][
Rescale[Sqrt[x^2 + y^2 + z^2], {minDist, maxDist}]]],
ColorFunctionScaling -> False,
Filling -> Axis,
BoxRatios -> {1, 1, 1},
PlotStyle -> PointSize[Large]],
BarLegend[{If[cf === Hue, Hue,
ColorData[cf][Rescale[#, {minDist, maxDist}]] &], {minDist, maxDist}}]],
{{cf, Hue, "ColorFunction"}, {Hue, "Rainbow", "TemperatureMap"}}]
$endgroup$
add a comment |
$begingroup$
ClearAll["Global`*"]
pointsChar = {{0.`, 0.`, 41.63`}, {8.50479382206883`, 0.`,
31.74032265185878`}, {14.975`, 0.`,
25.937460843343935`}, {19.69999492385721`, 0.`,
19.69999492385721`}, {23.053596248741755`, 0.`,
13.31`}, {25.12373074177866`, 0.`, 6.731883363116563`}, {26.16`, 0.`,
0.`}, {26.205567667222418`,
0.`, -7.0217606936313866`}, {24.595121467478055`,
0.`, -14.2`}, {21.630396436496486`, 0.`, -21.630396436496486`}, {16.62`,
0.`, -28.786684421794742`}, {10.396761041768258`,
0.`, -38.80124044203187`}};
{minDist, maxDist} = MinMax[EuclideanDistance[{0, 0, 0}, #] & /@ pointsChar];
Since colors given by Hue
are the same for min and max values, an alternative color function may be desired. Further, the EuclideanDistance
is given in the Tooltip
.
Manipulate[
Legended[
ListPointPlot3D[
Tooltip[#, EuclideanDistance[{0, 0, 0}, #]] & /@
pointsChar,
ColorFunction ->
Function[{x, y, z},
If[cf === Hue, Hue, ColorData[cf]][
Rescale[Sqrt[x^2 + y^2 + z^2], {minDist, maxDist}]]],
ColorFunctionScaling -> False,
Filling -> Axis,
BoxRatios -> {1, 1, 1},
PlotStyle -> PointSize[Large]],
BarLegend[{If[cf === Hue, Hue,
ColorData[cf][Rescale[#, {minDist, maxDist}]] &], {minDist, maxDist}}]],
{{cf, Hue, "ColorFunction"}, {Hue, "Rainbow", "TemperatureMap"}}]
$endgroup$
ClearAll["Global`*"]
pointsChar = {{0.`, 0.`, 41.63`}, {8.50479382206883`, 0.`,
31.74032265185878`}, {14.975`, 0.`,
25.937460843343935`}, {19.69999492385721`, 0.`,
19.69999492385721`}, {23.053596248741755`, 0.`,
13.31`}, {25.12373074177866`, 0.`, 6.731883363116563`}, {26.16`, 0.`,
0.`}, {26.205567667222418`,
0.`, -7.0217606936313866`}, {24.595121467478055`,
0.`, -14.2`}, {21.630396436496486`, 0.`, -21.630396436496486`}, {16.62`,
0.`, -28.786684421794742`}, {10.396761041768258`,
0.`, -38.80124044203187`}};
{minDist, maxDist} = MinMax[EuclideanDistance[{0, 0, 0}, #] & /@ pointsChar];
Since colors given by Hue
are the same for min and max values, an alternative color function may be desired. Further, the EuclideanDistance
is given in the Tooltip
.
Manipulate[
Legended[
ListPointPlot3D[
Tooltip[#, EuclideanDistance[{0, 0, 0}, #]] & /@
pointsChar,
ColorFunction ->
Function[{x, y, z},
If[cf === Hue, Hue, ColorData[cf]][
Rescale[Sqrt[x^2 + y^2 + z^2], {minDist, maxDist}]]],
ColorFunctionScaling -> False,
Filling -> Axis,
BoxRatios -> {1, 1, 1},
PlotStyle -> PointSize[Large]],
BarLegend[{If[cf === Hue, Hue,
ColorData[cf][Rescale[#, {minDist, maxDist}]] &], {minDist, maxDist}}]],
{{cf, Hue, "ColorFunction"}, {Hue, "Rainbow", "TemperatureMap"}}]
answered Nov 16 '18 at 22:20
Bob HanlonBob Hanlon
59.5k33596
59.5k33596
add a comment |
add a comment |
$begingroup$
You can extract the Point
primitives and their styles from ListPointPlot3D
output and use them to construct a PointLegend
:
lpp = ListPointPlot3D[pointsChar,
ColorFunction -> Function[{x, y, z}, Hue[Sqrt[x^2 + y^2 + z^2]]],
Filling -> Axis, BoxRatios -> {1, 1, 1},
PlotStyle -> PointSize[Large]];
legend = PointLegend[## & @@ Transpose[Cases[lpp, {a_, Point[b_]} :> {a, b}, ∞]],
LegendMarkerSize -> 20];
Legended[lpp, legend]
$endgroup$
add a comment |
$begingroup$
You can extract the Point
primitives and their styles from ListPointPlot3D
output and use them to construct a PointLegend
:
lpp = ListPointPlot3D[pointsChar,
ColorFunction -> Function[{x, y, z}, Hue[Sqrt[x^2 + y^2 + z^2]]],
Filling -> Axis, BoxRatios -> {1, 1, 1},
PlotStyle -> PointSize[Large]];
legend = PointLegend[## & @@ Transpose[Cases[lpp, {a_, Point[b_]} :> {a, b}, ∞]],
LegendMarkerSize -> 20];
Legended[lpp, legend]
$endgroup$
add a comment |
$begingroup$
You can extract the Point
primitives and their styles from ListPointPlot3D
output and use them to construct a PointLegend
:
lpp = ListPointPlot3D[pointsChar,
ColorFunction -> Function[{x, y, z}, Hue[Sqrt[x^2 + y^2 + z^2]]],
Filling -> Axis, BoxRatios -> {1, 1, 1},
PlotStyle -> PointSize[Large]];
legend = PointLegend[## & @@ Transpose[Cases[lpp, {a_, Point[b_]} :> {a, b}, ∞]],
LegendMarkerSize -> 20];
Legended[lpp, legend]
$endgroup$
You can extract the Point
primitives and their styles from ListPointPlot3D
output and use them to construct a PointLegend
:
lpp = ListPointPlot3D[pointsChar,
ColorFunction -> Function[{x, y, z}, Hue[Sqrt[x^2 + y^2 + z^2]]],
Filling -> Axis, BoxRatios -> {1, 1, 1},
PlotStyle -> PointSize[Large]];
legend = PointLegend[## & @@ Transpose[Cases[lpp, {a_, Point[b_]} :> {a, b}, ∞]],
LegendMarkerSize -> 20];
Legended[lpp, legend]
answered Nov 16 '18 at 18:18
kglrkglr
181k10200413
181k10200413
add a comment |
add a comment |
Thanks for contributing an answer to Mathematica 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.
Use MathJax to format equations. MathJax reference.
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%2fmathematica.stackexchange.com%2fquestions%2f186133%2fis-it-possible-to-add-the-coloring-range-as-legend%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
2
$begingroup$
You can generate your legend using
BarLegend[{Hue,MinMax[EuclideanDistance[{0,0,0},#]&/@pointsChar]}]
.$endgroup$
– N.J.Evans
Nov 16 '18 at 17:25
$begingroup$
Legended[ YYYYY , XXXX ] where YYYY your plot function as is and XXXX the legend code from @N.J. Evans, separated by a comma. I was happening to be working on the same problem but I could not match the colours with the legend. Maybe a complete answer can be posted by the first commentator...?
$endgroup$
– Titus
Nov 16 '18 at 17:52