ColorFunction based on array index in ListLinePlotListContourPlot-ColorFunctionUse ColorFunction in ListLinePlot with IfAdapt ColorFunction in Array PlotColorFunction based on dataColorFunction for even rows in an arrayWhy does not ListLinePlot work with a new defined ColorFunction?Independent Colorfunction in RevolutionPlot3D
Interaction between Teferi Time Raveler and Enduring Ideal
Some Prime Peerage
What are examples of experiments or studies where pre-registration would not be feasible?
Are space camera sensors usually round, or square?
Is using gradient descent for MIP a good idea?
How To Make Earth's Oceans as Brackish as Lyr's
If I want an interpretable model, are there methods other than Linear Regression?
Can I fix my boots by gluing the soles back on?
Is there any reason to concentrate on the Thunderous Smite spell after using its effects?
Are there any “Third Order” acronyms used in space exploration?
How do certain apps show new notifications when internet access is restricted to them?
Is Schwarzschild's solution in his original paper consistent with current solutions?
What do the French say for “Oh, you shouldn’t have”?
Does my opponent need to prove his creature has morph?
Why is the year in this ISO timestamp not 2019?
What made 4/4 time the most common time signature?
Why don't Wizards use wrist straps to protect against disarming charms?
What is this gigantic dish at Ben Gurion airport?
In what sequence should an advanced civilization teach technology to medieval society to maximize rate of adoption?
Has SHA256 been broken by Treadwell Stanton DuPont?
How would you control supersoldiers in a late iron-age society?
Speedometer as a symbol into awesomebox
How to conditionally add the "show-row-number-column" attribute to the lightning-datatable
I am getting "syntax error near unexpected token `'$#''" in a simple Bash script
ColorFunction based on array index in ListLinePlot
ListContourPlot-ColorFunctionUse ColorFunction in ListLinePlot with IfAdapt ColorFunction in Array PlotColorFunction based on dataColorFunction for even rows in an arrayWhy does not ListLinePlot work with a new defined ColorFunction?Independent Colorfunction in RevolutionPlot3D
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
ColorFunction specifies that for ListLinePlot it takes the $x,y$ data as inputs. I, however, would like to take the array index (or in general some external array of the same length) as the input for ColorFunction so that, if we use a rainbow color scheme, the earlier points show up as purple while the last points show up as red. An application would be visualisation of the long time behaviour of some system when data is imported from an external source.
For example if we take
ListLinePlot[Table[E^-0.001 x Cos[x], Sin[x], x, 0, 100, 0.1]]
then the outer lines should be purple ending up as red as the plot spirals in.
plotting
$endgroup$
add a comment
|
$begingroup$
ColorFunction specifies that for ListLinePlot it takes the $x,y$ data as inputs. I, however, would like to take the array index (or in general some external array of the same length) as the input for ColorFunction so that, if we use a rainbow color scheme, the earlier points show up as purple while the last points show up as red. An application would be visualisation of the long time behaviour of some system when data is imported from an external source.
For example if we take
ListLinePlot[Table[E^-0.001 x Cos[x], Sin[x], x, 0, 100, 0.1]]
then the outer lines should be purple ending up as red as the plot spirals in.
plotting
$endgroup$
add a comment
|
$begingroup$
ColorFunction specifies that for ListLinePlot it takes the $x,y$ data as inputs. I, however, would like to take the array index (or in general some external array of the same length) as the input for ColorFunction so that, if we use a rainbow color scheme, the earlier points show up as purple while the last points show up as red. An application would be visualisation of the long time behaviour of some system when data is imported from an external source.
For example if we take
ListLinePlot[Table[E^-0.001 x Cos[x], Sin[x], x, 0, 100, 0.1]]
then the outer lines should be purple ending up as red as the plot spirals in.
plotting
$endgroup$
ColorFunction specifies that for ListLinePlot it takes the $x,y$ data as inputs. I, however, would like to take the array index (or in general some external array of the same length) as the input for ColorFunction so that, if we use a rainbow color scheme, the earlier points show up as purple while the last points show up as red. An application would be visualisation of the long time behaviour of some system when data is imported from an external source.
For example if we take
ListLinePlot[Table[E^-0.001 x Cos[x], Sin[x], x, 0, 100, 0.1]]
then the outer lines should be purple ending up as red as the plot spirals in.
plotting
plotting
edited 8 hours ago
Takoda
asked 8 hours ago
TakodaTakoda
3618 bronze badges
3618 bronze badges
add a comment
|
add a comment
|
3 Answers
3
active
oldest
votes
$begingroup$
data = Table[E^-0.001 x Cos[x], Sin[x], x, 0, 100, 0.1];
indexlist = Rescale[Range @ Length @ data] (* or your external list to control color*);
iF = Interpolation[MapThread[#, #2 &, data, indexlist], InterpolationOrder -> 1];
ListLinePlot[data,
AspectRatio -> 1,
ColorFunctionScaling -> False,
ColorFunction -> (ColorData["Rainbow", "Reversed"][ iF[#, #2]]&)]

Alternative methods:
PolarPlot
PolarPlot[E^-0.001 x , x, 0, 100,
ColorFunction -> (ColorData["Rainbow", "Reversed"][#3] &)
same picture
ParametricPlot
ParametricPlot[E^-0.001 x Cos[x], Sin[x], x, 0, 100,
ColorFunction -> (ColorData["Rainbow", "Reversed"][#3] &)]
same picture
Graphics + VertexColors
Graphics[Line[data, VertexColors -> (ColorData["Rainbow", "Reversed"] /@ indexlist)],
Axes -> True]
same picture
$endgroup$
$begingroup$
This is a good answer, but I think you want(ColorData["Rainbow", "Reverse"]to satisfy the OP's coloring order.
$endgroup$
– m_goldberg
7 hours ago
1
$begingroup$
Thank you @m_goldberg.ColorData["Rainbow", "Reversed"]andColorData["Rainbow", "Reverse"]both work.
$endgroup$
– kglr
7 hours ago
$begingroup$
You're right, they both work. Your solution is independent of the ordering of the Rainbow color scheme. Still, I feel a little stupid about making my original comment.
$endgroup$
– m_goldberg
7 hours ago
add a comment
|
$begingroup$
With[lines=Line/@Partition[Table[E^-0.001 x Cos[x], Sin[x], x, 0, 100, 0.1],2,1],
Graphics[MapIndexed[ColorData["Rainbow","Reverse"][First@#2/Length[lines]],#1&,lines],
Frame -> True]]

$endgroup$
add a comment
|
$begingroup$
I think it is easier to generate the plot you want with ParametricPlot Like so:
With[n = 100,
ParametricPlot[E^-0.001 x Cos[x], Sin[x], x, 0, n,
Mesh -> n - 1,
MeshStyle -> Transparent,
MeshShading ->Table[ColorData[L"Rainbow", "Reverse"][i/n], i, n]]]

$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/4.0/"u003ecc by-sa 4.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%2f206189%2fcolorfunction-based-on-array-index-in-listlineplot%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
data = Table[E^-0.001 x Cos[x], Sin[x], x, 0, 100, 0.1];
indexlist = Rescale[Range @ Length @ data] (* or your external list to control color*);
iF = Interpolation[MapThread[#, #2 &, data, indexlist], InterpolationOrder -> 1];
ListLinePlot[data,
AspectRatio -> 1,
ColorFunctionScaling -> False,
ColorFunction -> (ColorData["Rainbow", "Reversed"][ iF[#, #2]]&)]

Alternative methods:
PolarPlot
PolarPlot[E^-0.001 x , x, 0, 100,
ColorFunction -> (ColorData["Rainbow", "Reversed"][#3] &)
same picture
ParametricPlot
ParametricPlot[E^-0.001 x Cos[x], Sin[x], x, 0, 100,
ColorFunction -> (ColorData["Rainbow", "Reversed"][#3] &)]
same picture
Graphics + VertexColors
Graphics[Line[data, VertexColors -> (ColorData["Rainbow", "Reversed"] /@ indexlist)],
Axes -> True]
same picture
$endgroup$
$begingroup$
This is a good answer, but I think you want(ColorData["Rainbow", "Reverse"]to satisfy the OP's coloring order.
$endgroup$
– m_goldberg
7 hours ago
1
$begingroup$
Thank you @m_goldberg.ColorData["Rainbow", "Reversed"]andColorData["Rainbow", "Reverse"]both work.
$endgroup$
– kglr
7 hours ago
$begingroup$
You're right, they both work. Your solution is independent of the ordering of the Rainbow color scheme. Still, I feel a little stupid about making my original comment.
$endgroup$
– m_goldberg
7 hours ago
add a comment
|
$begingroup$
data = Table[E^-0.001 x Cos[x], Sin[x], x, 0, 100, 0.1];
indexlist = Rescale[Range @ Length @ data] (* or your external list to control color*);
iF = Interpolation[MapThread[#, #2 &, data, indexlist], InterpolationOrder -> 1];
ListLinePlot[data,
AspectRatio -> 1,
ColorFunctionScaling -> False,
ColorFunction -> (ColorData["Rainbow", "Reversed"][ iF[#, #2]]&)]

Alternative methods:
PolarPlot
PolarPlot[E^-0.001 x , x, 0, 100,
ColorFunction -> (ColorData["Rainbow", "Reversed"][#3] &)
same picture
ParametricPlot
ParametricPlot[E^-0.001 x Cos[x], Sin[x], x, 0, 100,
ColorFunction -> (ColorData["Rainbow", "Reversed"][#3] &)]
same picture
Graphics + VertexColors
Graphics[Line[data, VertexColors -> (ColorData["Rainbow", "Reversed"] /@ indexlist)],
Axes -> True]
same picture
$endgroup$
$begingroup$
This is a good answer, but I think you want(ColorData["Rainbow", "Reverse"]to satisfy the OP's coloring order.
$endgroup$
– m_goldberg
7 hours ago
1
$begingroup$
Thank you @m_goldberg.ColorData["Rainbow", "Reversed"]andColorData["Rainbow", "Reverse"]both work.
$endgroup$
– kglr
7 hours ago
$begingroup$
You're right, they both work. Your solution is independent of the ordering of the Rainbow color scheme. Still, I feel a little stupid about making my original comment.
$endgroup$
– m_goldberg
7 hours ago
add a comment
|
$begingroup$
data = Table[E^-0.001 x Cos[x], Sin[x], x, 0, 100, 0.1];
indexlist = Rescale[Range @ Length @ data] (* or your external list to control color*);
iF = Interpolation[MapThread[#, #2 &, data, indexlist], InterpolationOrder -> 1];
ListLinePlot[data,
AspectRatio -> 1,
ColorFunctionScaling -> False,
ColorFunction -> (ColorData["Rainbow", "Reversed"][ iF[#, #2]]&)]

Alternative methods:
PolarPlot
PolarPlot[E^-0.001 x , x, 0, 100,
ColorFunction -> (ColorData["Rainbow", "Reversed"][#3] &)
same picture
ParametricPlot
ParametricPlot[E^-0.001 x Cos[x], Sin[x], x, 0, 100,
ColorFunction -> (ColorData["Rainbow", "Reversed"][#3] &)]
same picture
Graphics + VertexColors
Graphics[Line[data, VertexColors -> (ColorData["Rainbow", "Reversed"] /@ indexlist)],
Axes -> True]
same picture
$endgroup$
data = Table[E^-0.001 x Cos[x], Sin[x], x, 0, 100, 0.1];
indexlist = Rescale[Range @ Length @ data] (* or your external list to control color*);
iF = Interpolation[MapThread[#, #2 &, data, indexlist], InterpolationOrder -> 1];
ListLinePlot[data,
AspectRatio -> 1,
ColorFunctionScaling -> False,
ColorFunction -> (ColorData["Rainbow", "Reversed"][ iF[#, #2]]&)]

Alternative methods:
PolarPlot
PolarPlot[E^-0.001 x , x, 0, 100,
ColorFunction -> (ColorData["Rainbow", "Reversed"][#3] &)
same picture
ParametricPlot
ParametricPlot[E^-0.001 x Cos[x], Sin[x], x, 0, 100,
ColorFunction -> (ColorData["Rainbow", "Reversed"][#3] &)]
same picture
Graphics + VertexColors
Graphics[Line[data, VertexColors -> (ColorData["Rainbow", "Reversed"] /@ indexlist)],
Axes -> True]
same picture
edited 7 hours ago
answered 8 hours ago
kglrkglr
216k10 gold badges246 silver badges496 bronze badges
216k10 gold badges246 silver badges496 bronze badges
$begingroup$
This is a good answer, but I think you want(ColorData["Rainbow", "Reverse"]to satisfy the OP's coloring order.
$endgroup$
– m_goldberg
7 hours ago
1
$begingroup$
Thank you @m_goldberg.ColorData["Rainbow", "Reversed"]andColorData["Rainbow", "Reverse"]both work.
$endgroup$
– kglr
7 hours ago
$begingroup$
You're right, they both work. Your solution is independent of the ordering of the Rainbow color scheme. Still, I feel a little stupid about making my original comment.
$endgroup$
– m_goldberg
7 hours ago
add a comment
|
$begingroup$
This is a good answer, but I think you want(ColorData["Rainbow", "Reverse"]to satisfy the OP's coloring order.
$endgroup$
– m_goldberg
7 hours ago
1
$begingroup$
Thank you @m_goldberg.ColorData["Rainbow", "Reversed"]andColorData["Rainbow", "Reverse"]both work.
$endgroup$
– kglr
7 hours ago
$begingroup$
You're right, they both work. Your solution is independent of the ordering of the Rainbow color scheme. Still, I feel a little stupid about making my original comment.
$endgroup$
– m_goldberg
7 hours ago
$begingroup$
This is a good answer, but I think you want
(ColorData["Rainbow", "Reverse"] to satisfy the OP's coloring order.$endgroup$
– m_goldberg
7 hours ago
$begingroup$
This is a good answer, but I think you want
(ColorData["Rainbow", "Reverse"] to satisfy the OP's coloring order.$endgroup$
– m_goldberg
7 hours ago
1
1
$begingroup$
Thank you @m_goldberg.
ColorData["Rainbow", "Reversed"] and ColorData["Rainbow", "Reverse"] both work.$endgroup$
– kglr
7 hours ago
$begingroup$
Thank you @m_goldberg.
ColorData["Rainbow", "Reversed"] and ColorData["Rainbow", "Reverse"] both work.$endgroup$
– kglr
7 hours ago
$begingroup$
You're right, they both work. Your solution is independent of the ordering of the Rainbow color scheme. Still, I feel a little stupid about making my original comment.
$endgroup$
– m_goldberg
7 hours ago
$begingroup$
You're right, they both work. Your solution is independent of the ordering of the Rainbow color scheme. Still, I feel a little stupid about making my original comment.
$endgroup$
– m_goldberg
7 hours ago
add a comment
|
$begingroup$
With[lines=Line/@Partition[Table[E^-0.001 x Cos[x], Sin[x], x, 0, 100, 0.1],2,1],
Graphics[MapIndexed[ColorData["Rainbow","Reverse"][First@#2/Length[lines]],#1&,lines],
Frame -> True]]

$endgroup$
add a comment
|
$begingroup$
With[lines=Line/@Partition[Table[E^-0.001 x Cos[x], Sin[x], x, 0, 100, 0.1],2,1],
Graphics[MapIndexed[ColorData["Rainbow","Reverse"][First@#2/Length[lines]],#1&,lines],
Frame -> True]]

$endgroup$
add a comment
|
$begingroup$
With[lines=Line/@Partition[Table[E^-0.001 x Cos[x], Sin[x], x, 0, 100, 0.1],2,1],
Graphics[MapIndexed[ColorData["Rainbow","Reverse"][First@#2/Length[lines]],#1&,lines],
Frame -> True]]

$endgroup$
With[lines=Line/@Partition[Table[E^-0.001 x Cos[x], Sin[x], x, 0, 100, 0.1],2,1],
Graphics[MapIndexed[ColorData["Rainbow","Reverse"][First@#2/Length[lines]],#1&,lines],
Frame -> True]]

answered 7 hours ago
AlxAlx
8884 silver badges9 bronze badges
8884 silver badges9 bronze badges
add a comment
|
add a comment
|
$begingroup$
I think it is easier to generate the plot you want with ParametricPlot Like so:
With[n = 100,
ParametricPlot[E^-0.001 x Cos[x], Sin[x], x, 0, n,
Mesh -> n - 1,
MeshStyle -> Transparent,
MeshShading ->Table[ColorData[L"Rainbow", "Reverse"][i/n], i, n]]]

$endgroup$
add a comment
|
$begingroup$
I think it is easier to generate the plot you want with ParametricPlot Like so:
With[n = 100,
ParametricPlot[E^-0.001 x Cos[x], Sin[x], x, 0, n,
Mesh -> n - 1,
MeshStyle -> Transparent,
MeshShading ->Table[ColorData[L"Rainbow", "Reverse"][i/n], i, n]]]

$endgroup$
add a comment
|
$begingroup$
I think it is easier to generate the plot you want with ParametricPlot Like so:
With[n = 100,
ParametricPlot[E^-0.001 x Cos[x], Sin[x], x, 0, n,
Mesh -> n - 1,
MeshStyle -> Transparent,
MeshShading ->Table[ColorData[L"Rainbow", "Reverse"][i/n], i, n]]]

$endgroup$
I think it is easier to generate the plot you want with ParametricPlot Like so:
With[n = 100,
ParametricPlot[E^-0.001 x Cos[x], Sin[x], x, 0, n,
Mesh -> n - 1,
MeshStyle -> Transparent,
MeshShading ->Table[ColorData[L"Rainbow", "Reverse"][i/n], i, n]]]

edited 7 hours ago
answered 7 hours ago
m_goldbergm_goldberg
91.6k8 gold badges75 silver badges209 bronze badges
91.6k8 gold badges75 silver badges209 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%2f206189%2fcolorfunction-based-on-array-index-in-listlineplot%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