Using `PlotLegends` with a `ColorFunction`Using PlotLegendsPlotLegends questionChange the legend labels' font when PlotLegends is AutomaticHow to simulate Placed in workaround for PlotLegends ParametricPlot bug?Piecewise ColorFunction for Plot3DHow to prevent ColorFunction from blending colors between points on a ListLinePlotListPlot with different color optionsMake Legend dot largerCommon legend for two density plotsColorFunction ranges for SphericalPlot3D
What specific instant in time in the MCU has been depicted the most times?
LED glows slightly during soldering
Why isn't pressure filtration popular compared to vacuum filtration?
Is it unbalanced to allow a monk with the Tavern Brawler feat to use improvised weapons as monk weapons?
Is it possible to create a craft with specific bones, like the bones of a forgotten beast?
Is there a strong legal guarantee that the U.S. can give to another country that it won't attack them?
Why weren't bootable game disks ever common on the IBM PC?
How can a dictatorship government be beneficial to a dictator in a post-scarcity society?
Great Unsolved Problems in O.R
Is a request to book a business flight ticket for a graduate student an unreasonable one?
How to deal with moral/legal subjects in writing?
Are there any sports for which the world's best player is female?
Why was hardware diversification an asset for the IBM PC ecosystem?
Would dual wielding daggers be a viable choice for a covert bodyguard?
Confirming the Identity of a (Friendly) Reviewer After the Reviews
Received a dinner invitation through my employer's email, is it ok to attend?
How to memorize multiple pieces?
Fivenum and a little bit
Graduate student with abysmal English writing skills, how to help
How can I fix the dull colors I am getting in Ubuntu 19.04 Terminal?
Why is the air gap between the stator and rotor on a motor kept as small as it is?
Why didn't Thanos kill all the Dwarves on Nidavellir?
Why is the ladder of the LM always in the dark side of the LM?
Are there any medieval light sources without fire?
Using `PlotLegends` with a `ColorFunction`
Using PlotLegendsPlotLegends questionChange the legend labels' font when PlotLegends is AutomaticHow to simulate Placed in workaround for PlotLegends ParametricPlot bug?Piecewise ColorFunction for Plot3DHow to prevent ColorFunction from blending colors between points on a ListLinePlotListPlot with different color optionsMake Legend dot largerCommon legend for two density plotsColorFunction ranges for SphericalPlot3D
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
Is there a way to put a legend mark with a color function rainbow?
For example:
legend2 =
Grid[Graphics[Red, Thick, Line[0, 0, 2, 0],
ImageSize -> 5], "u"]
u[x_] := x
Plot[u[x], x, 0, 1, ColorFunction -> "Rainbow",
PlotLegends -> Placed[legend2, 1.05, 0.5, 0, 0.5]]
In this case the plot marker is red. Is there a way to put a rainbow scale like the function?
plotting legending
$endgroup$
add a comment |
$begingroup$
Is there a way to put a legend mark with a color function rainbow?
For example:
legend2 =
Grid[Graphics[Red, Thick, Line[0, 0, 2, 0],
ImageSize -> 5], "u"]
u[x_] := x
Plot[u[x], x, 0, 1, ColorFunction -> "Rainbow",
PlotLegends -> Placed[legend2, 1.05, 0.5, 0, 0.5]]
In this case the plot marker is red. Is there a way to put a rainbow scale like the function?
plotting legending
$endgroup$
$begingroup$
I don't want a bar. I want a line (like the image) but instead the color red, a rainbow color.
$endgroup$
– Mateus
7 hours ago
add a comment |
$begingroup$
Is there a way to put a legend mark with a color function rainbow?
For example:
legend2 =
Grid[Graphics[Red, Thick, Line[0, 0, 2, 0],
ImageSize -> 5], "u"]
u[x_] := x
Plot[u[x], x, 0, 1, ColorFunction -> "Rainbow",
PlotLegends -> Placed[legend2, 1.05, 0.5, 0, 0.5]]
In this case the plot marker is red. Is there a way to put a rainbow scale like the function?
plotting legending
$endgroup$
Is there a way to put a legend mark with a color function rainbow?
For example:
legend2 =
Grid[Graphics[Red, Thick, Line[0, 0, 2, 0],
ImageSize -> 5], "u"]
u[x_] := x
Plot[u[x], x, 0, 1, ColorFunction -> "Rainbow",
PlotLegends -> Placed[legend2, 1.05, 0.5, 0, 0.5]]
In this case the plot marker is red. Is there a way to put a rainbow scale like the function?
plotting legending
plotting legending
asked 9 hours ago
MateusMateus
6241 silver badge7 bronze badges
6241 silver badge7 bronze badges
$begingroup$
I don't want a bar. I want a line (like the image) but instead the color red, a rainbow color.
$endgroup$
– Mateus
7 hours ago
add a comment |
$begingroup$
I don't want a bar. I want a line (like the image) but instead the color red, a rainbow color.
$endgroup$
– Mateus
7 hours ago
$begingroup$
I don't want a bar. I want a line (like the image) but instead the color red, a rainbow color.
$endgroup$
– Mateus
7 hours ago
$begingroup$
I don't want a bar. I want a line (like the image) but instead the color red, a rainbow color.
$endgroup$
– Mateus
7 hours ago
add a comment |
2 Answers
2
active
oldest
votes
$begingroup$
u[x_] := x
sparkline = Plot[0, x, 0, 1,
ColorFunction -> (ColorData[ "Rainbow"][#] &),
PlotStyle -> Thick,
PlotTheme -> "Sparkline", Axes -> False];
Plot[u[x], x, 0, 1,
ColorFunction -> "Rainbow",
PlotStyle -> Thick,
PlotLegends -> Labeled[sparkline, "u", Right]]
An alternative ways is to use sparkline
with the (undocumented) option "LegendItem"
inside LineLegend
:
Plot[u[x], x, 0, 1,
ColorFunction -> "Rainbow",
PlotStyle -> Thick,
PlotLegends -> LineLegend[Automatic, u, "LegendItem" -> sparkline]]
Variations on the same idea:
colorfunctions = "Rainbow", "SolarColors";
functions = Sin[x], Cos[x];
sparklines = MapThread[Plot[#, x, 0, 2 Pi,
ColorFunction -> #2, PlotStyle -> Thick,
PlotTheme -> "Sparkline", Axes -> False] &,
functions, colorfunctions];
Show[MapThread[Plot[#, x, 0, 2 Pi,
ColorFunction -> #2, PlotStyle -> Thick,
PlotLegends -> LineLegend[Automatic, TraditionalForm @ #,
"LegendItem" -> #3, LegendMarkerSize -> Large]] &,
functions, colorfunctions, sparklines]]
$endgroup$
add a comment |
$begingroup$
You can use LegendLayout
to modify the Line[]
in LineLegend
:
ClearAll[cfline];
cfline[cf_String] := cfline[ColorData@cf];
cfline[cf_][pairs_] := Grid[
pairs /.
Line[a_, b_] :>
Line[Subdivide[a, b, 20],
VertexColors -> cf /@ Subdivide[0., 1., 20]]
];
Plot[u[x], x, 0, 4,
ColorFunction -> "Rainbow",
PlotLegends -> LineLegend["Expressions", LegendLayout -> cfline@"Rainbow"]]
$endgroup$
add a comment |
Your Answer
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%2f201821%2fusing-plotlegends-with-a-colorfunction%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$
u[x_] := x
sparkline = Plot[0, x, 0, 1,
ColorFunction -> (ColorData[ "Rainbow"][#] &),
PlotStyle -> Thick,
PlotTheme -> "Sparkline", Axes -> False];
Plot[u[x], x, 0, 1,
ColorFunction -> "Rainbow",
PlotStyle -> Thick,
PlotLegends -> Labeled[sparkline, "u", Right]]
An alternative ways is to use sparkline
with the (undocumented) option "LegendItem"
inside LineLegend
:
Plot[u[x], x, 0, 1,
ColorFunction -> "Rainbow",
PlotStyle -> Thick,
PlotLegends -> LineLegend[Automatic, u, "LegendItem" -> sparkline]]
Variations on the same idea:
colorfunctions = "Rainbow", "SolarColors";
functions = Sin[x], Cos[x];
sparklines = MapThread[Plot[#, x, 0, 2 Pi,
ColorFunction -> #2, PlotStyle -> Thick,
PlotTheme -> "Sparkline", Axes -> False] &,
functions, colorfunctions];
Show[MapThread[Plot[#, x, 0, 2 Pi,
ColorFunction -> #2, PlotStyle -> Thick,
PlotLegends -> LineLegend[Automatic, TraditionalForm @ #,
"LegendItem" -> #3, LegendMarkerSize -> Large]] &,
functions, colorfunctions, sparklines]]
$endgroup$
add a comment |
$begingroup$
u[x_] := x
sparkline = Plot[0, x, 0, 1,
ColorFunction -> (ColorData[ "Rainbow"][#] &),
PlotStyle -> Thick,
PlotTheme -> "Sparkline", Axes -> False];
Plot[u[x], x, 0, 1,
ColorFunction -> "Rainbow",
PlotStyle -> Thick,
PlotLegends -> Labeled[sparkline, "u", Right]]
An alternative ways is to use sparkline
with the (undocumented) option "LegendItem"
inside LineLegend
:
Plot[u[x], x, 0, 1,
ColorFunction -> "Rainbow",
PlotStyle -> Thick,
PlotLegends -> LineLegend[Automatic, u, "LegendItem" -> sparkline]]
Variations on the same idea:
colorfunctions = "Rainbow", "SolarColors";
functions = Sin[x], Cos[x];
sparklines = MapThread[Plot[#, x, 0, 2 Pi,
ColorFunction -> #2, PlotStyle -> Thick,
PlotTheme -> "Sparkline", Axes -> False] &,
functions, colorfunctions];
Show[MapThread[Plot[#, x, 0, 2 Pi,
ColorFunction -> #2, PlotStyle -> Thick,
PlotLegends -> LineLegend[Automatic, TraditionalForm @ #,
"LegendItem" -> #3, LegendMarkerSize -> Large]] &,
functions, colorfunctions, sparklines]]
$endgroup$
add a comment |
$begingroup$
u[x_] := x
sparkline = Plot[0, x, 0, 1,
ColorFunction -> (ColorData[ "Rainbow"][#] &),
PlotStyle -> Thick,
PlotTheme -> "Sparkline", Axes -> False];
Plot[u[x], x, 0, 1,
ColorFunction -> "Rainbow",
PlotStyle -> Thick,
PlotLegends -> Labeled[sparkline, "u", Right]]
An alternative ways is to use sparkline
with the (undocumented) option "LegendItem"
inside LineLegend
:
Plot[u[x], x, 0, 1,
ColorFunction -> "Rainbow",
PlotStyle -> Thick,
PlotLegends -> LineLegend[Automatic, u, "LegendItem" -> sparkline]]
Variations on the same idea:
colorfunctions = "Rainbow", "SolarColors";
functions = Sin[x], Cos[x];
sparklines = MapThread[Plot[#, x, 0, 2 Pi,
ColorFunction -> #2, PlotStyle -> Thick,
PlotTheme -> "Sparkline", Axes -> False] &,
functions, colorfunctions];
Show[MapThread[Plot[#, x, 0, 2 Pi,
ColorFunction -> #2, PlotStyle -> Thick,
PlotLegends -> LineLegend[Automatic, TraditionalForm @ #,
"LegendItem" -> #3, LegendMarkerSize -> Large]] &,
functions, colorfunctions, sparklines]]
$endgroup$
u[x_] := x
sparkline = Plot[0, x, 0, 1,
ColorFunction -> (ColorData[ "Rainbow"][#] &),
PlotStyle -> Thick,
PlotTheme -> "Sparkline", Axes -> False];
Plot[u[x], x, 0, 1,
ColorFunction -> "Rainbow",
PlotStyle -> Thick,
PlotLegends -> Labeled[sparkline, "u", Right]]
An alternative ways is to use sparkline
with the (undocumented) option "LegendItem"
inside LineLegend
:
Plot[u[x], x, 0, 1,
ColorFunction -> "Rainbow",
PlotStyle -> Thick,
PlotLegends -> LineLegend[Automatic, u, "LegendItem" -> sparkline]]
Variations on the same idea:
colorfunctions = "Rainbow", "SolarColors";
functions = Sin[x], Cos[x];
sparklines = MapThread[Plot[#, x, 0, 2 Pi,
ColorFunction -> #2, PlotStyle -> Thick,
PlotTheme -> "Sparkline", Axes -> False] &,
functions, colorfunctions];
Show[MapThread[Plot[#, x, 0, 2 Pi,
ColorFunction -> #2, PlotStyle -> Thick,
PlotLegends -> LineLegend[Automatic, TraditionalForm @ #,
"LegendItem" -> #3, LegendMarkerSize -> Large]] &,
functions, colorfunctions, sparklines]]
edited 5 hours ago
answered 7 hours ago
kglrkglr
204k10 gold badges233 silver badges463 bronze badges
204k10 gold badges233 silver badges463 bronze badges
add a comment |
add a comment |
$begingroup$
You can use LegendLayout
to modify the Line[]
in LineLegend
:
ClearAll[cfline];
cfline[cf_String] := cfline[ColorData@cf];
cfline[cf_][pairs_] := Grid[
pairs /.
Line[a_, b_] :>
Line[Subdivide[a, b, 20],
VertexColors -> cf /@ Subdivide[0., 1., 20]]
];
Plot[u[x], x, 0, 4,
ColorFunction -> "Rainbow",
PlotLegends -> LineLegend["Expressions", LegendLayout -> cfline@"Rainbow"]]
$endgroup$
add a comment |
$begingroup$
You can use LegendLayout
to modify the Line[]
in LineLegend
:
ClearAll[cfline];
cfline[cf_String] := cfline[ColorData@cf];
cfline[cf_][pairs_] := Grid[
pairs /.
Line[a_, b_] :>
Line[Subdivide[a, b, 20],
VertexColors -> cf /@ Subdivide[0., 1., 20]]
];
Plot[u[x], x, 0, 4,
ColorFunction -> "Rainbow",
PlotLegends -> LineLegend["Expressions", LegendLayout -> cfline@"Rainbow"]]
$endgroup$
add a comment |
$begingroup$
You can use LegendLayout
to modify the Line[]
in LineLegend
:
ClearAll[cfline];
cfline[cf_String] := cfline[ColorData@cf];
cfline[cf_][pairs_] := Grid[
pairs /.
Line[a_, b_] :>
Line[Subdivide[a, b, 20],
VertexColors -> cf /@ Subdivide[0., 1., 20]]
];
Plot[u[x], x, 0, 4,
ColorFunction -> "Rainbow",
PlotLegends -> LineLegend["Expressions", LegendLayout -> cfline@"Rainbow"]]
$endgroup$
You can use LegendLayout
to modify the Line[]
in LineLegend
:
ClearAll[cfline];
cfline[cf_String] := cfline[ColorData@cf];
cfline[cf_][pairs_] := Grid[
pairs /.
Line[a_, b_] :>
Line[Subdivide[a, b, 20],
VertexColors -> cf /@ Subdivide[0., 1., 20]]
];
Plot[u[x], x, 0, 4,
ColorFunction -> "Rainbow",
PlotLegends -> LineLegend["Expressions", LegendLayout -> cfline@"Rainbow"]]
answered 5 hours ago
Michael E2Michael E2
155k12 gold badges213 silver badges502 bronze badges
155k12 gold badges213 silver badges502 bronze badges
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%2f201821%2fusing-plotlegends-with-a-colorfunction%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
$begingroup$
I don't want a bar. I want a line (like the image) but instead the color red, a rainbow color.
$endgroup$
– Mateus
7 hours ago