0

The code used to work when I had manually created the variables instead of using a Do Loop to automatically generate variables. I've used both PlotStyle and ColorFunction but none of them works.

This part sets the initial conditions for the functions and plots

R[r_] := 2/(5*3)*1/(2*3)!*((2*r)/(5*3))^(2*3)*E^((-2*r)/(5*3))
SampleInitialConditions = N[Table[R[r], {r, 0, 100, 4}]];
SampleInitialConditionsMatrix = 
    List@N[Table[{r, R[r]}, {r, 0, 100, 4}]];
ALPHAkWITH = Table[0.002*Mass*Radius, {Mass, 1, 6}, {Radius, 1, 6}];

ALPHAkWITHOUT = Table[0.001MassRadius, {Mass, 1, 6}, {Radius, 1, 6}];

    LabelString = Table[StringForm["\[NumberSign] ``", LS], {LS, 1, 25}];
ColorList = {Table[{Blend[{Blue, Green, Yellow, Red, Brown}, 
       InitialCond]}, {InitialCond, 
            1/25, 1, 1/25}]} // Flatten;

These variables create the variables for the legends

    LegendWith = 
    SwatchLegend[ColorList, LabelString, 
      LegendLabel -> "With Photophoresis", LegendFunction -> "Frame", 
      LegendLayout -> "Row"];
LegendWithout = 
    SwatchLegend[ColorList, LabelString, 
      LegendLabel -> "Without Photophoresis", 
   LegendFunction -> "Frame", 
      LegendLayout -> "Row"];
LegendInitialConditions = 
    SwatchLegend[ColorList, LabelString, 
      LegendLabel -> "Initial Conditions", LegendFunction -> "Frame", 
      LegendLayout -> "Row"];

These Do Loop creates multiple NDSolve solutions for Differential Equations, it creates 36 Variables (6X6). There are 2 Loops, one is DiffequaWith and one is DiffequaWithout, each of those loops are lists that contain 25 Elements in them.

Do[
 ToExpression[
    "DiffequaWith\[VerticalLine]\[NumberSign]" <> ToString[Mass] <> 
   "\[VerticalLine]§\[VerticalLine]\[NumberSign]" <> 
   ToString[Radius] <> "\[VerticalLine]", StandardForm,
    Function[sym,
     sym = 
      Table[NDSolve[{q[\[Phi]] +
     q''[\[Phi]] == -(ALPHAkWITH[[Mass, 
         Radius]]/(1 + q[\[Phi]]))^2, 
        q[0] == R[r], q'[0] == R[r]}, q, {\[Phi], 0, 100}], {r, 
  0, 100, 
      4}]

, HoldAll] ], {Mass, 1, 6}, {Radius, 1, 6} ]

Do[

ToExpression[ "DiffequaWithout[VerticalLine][NumberSign]" <> ToString[Mass] <> "[VerticalLine]§[VerticalLine][NumberSign]" <> ToString[Radius] <> "[VerticalLine]", StandardForm, Function[sym,   sym = Table[NDSolve[{q[[Phi]] +

     q''[\[Phi]] == -(ALPHAkWITHOUT[[Mass, 
         Radius]]/(1 + q[\[Phi]]))^2, 
        q[0] == R[r], q'[0] == R[r]}, q, {\[Phi], 0, 100}], {r, 
  0, 100, 
      4}]

, HoldAll] ], {Mass, 1, 6}, {Radius, 1, 6} ]

These equations create variables that Evaluate the Numerically solved Differential Equations. Each of these loops also create 36 Variables that are Tables with 25 elements inside every variable.

Do[
  ToExpression[
    "CartesianEvaluateWith\[VerticalLine]\[NumberSign]" <> 
   ToString[Mass] <> "\[VerticalLine]§\[VerticalLine]\[NumberSign]" <> 
   ToString[Radius] <> "\[VerticalLine]", StandardForm,
    Function[sym, 
      sym = 
    Evaluate[
     q[\[Phi]] /. 
      ToExpression[
       "DiffequaWith\[VerticalLine]\[NumberSign]" <> ToString[Mass] <> 
        "\[VerticalLine]§\[VerticalLine]\[NumberSign]" <> 
        ToString[Radius] <> "\[VerticalLine]"]], 
      HoldAll]
    ],
  {Mass, 1, 6}, {Radius, 1, 6}
  ]
 
Do[
  ToExpression[
    "CartesianEvaluateWithout\[VerticalLine]\[NumberSign]" <> 
   ToString[Mass] <> "\[VerticalLine]§\[VerticalLine]\[NumberSign]" <> 
   ToString[Radius] <> "\[VerticalLine]", StandardForm,
    Function[sym, 
      sym =  
    Evaluate[
     q[\[Phi]] /. 
      ToExpression[
       "DiffequaWithout\[VerticalLine]\[NumberSign]" <> 
        ToString[Mass] <> 
        "\[VerticalLine]§\[VerticalLine]\[NumberSign]" <> 
        ToString[Radius] <> "\[VerticalLine]"]], 
      HoldAll]
    ],
  {Mass, 1, 6}, {Radius, 1, 6}
  ]

These Variables Plot the Evaluated Variables generated from before. The Problem comes from this, where the Plotstyle (or ColorFunction) only takes the Brown Color for all of the curves in the plot.

Do[
  ToExpression[
    "CartesianPlotWith\[VerticalLine]\[NumberSign]" <> 
   ToString[Mass] <> "\[VerticalLine]§\[VerticalLine]\[NumberSign]" <> 
   ToString[Radius] <> "\[VerticalLine]", StandardForm,
    Function[sym, 
      sym = 
    Plot[ToExpression[
      "CartesianEvaluateWith\[VerticalLine]\[NumberSign]" <> 
       ToString[Mass] <> 
       "\[VerticalLine]§\[VerticalLine]\[NumberSign]" <> 
       ToString[Radius] <> "\[VerticalLine]"], {\[Phi], 0, 100}, 
     PlotLabels ->
  Table[Callout[
    &quot;With Photohoresis \[NumberSign] &quot; &lt;&gt; ToString[InitialCond], 
    Above], {InitialCond, 
          1, Length[SampleInitialConditions]}], 
 PlotStyle -&gt; Table[ColorList[[T]], {T, 0, 25}], 
    PlotLegends -&gt; Placed[LegendWith, {Top, Left}], 
 ImageSize -&gt; 900], 
  HoldAll]
],

{Mass, 1, 6}, {Radius, 1, 6} ]   Do[ ToExpression[ "CartesianPlotWithout[VerticalLine][NumberSign]" <> ToString[Mass] <> "[VerticalLine]§[VerticalLine][NumberSign]" <> ToString[Radius] <> "[VerticalLine]", StandardForm, Function[sym, sym =
Plot[ToExpression[ "CartesianEvaluateWithout[VerticalLine][NumberSign]" <> ToString[Mass] <> "[VerticalLine]§[VerticalLine][NumberSign]" <> ToString[Radius] <> "[VerticalLine]"], {[Phi], 0, 100}, PlotLabels ->

  Table[Callout[
    &quot;Without Photophoresis \[NumberSign] &quot; &lt;&gt; 
     ToString[InitialCond], 
          Below], {InitialCond, 1, 
    Length[SampleInitialConditions]}], 
 PlotStyle -&gt; Table[ColorList[[T]], {T, 0, 25}], 
    PlotLegends -&gt; Placed[LegendWithout, {Bottom, Right}], 
    ImageSize -&gt; 900], 
  HoldAll]
],

{Mass, 1, 6}, {Radius, 1, 6} ]  

This Plot combines the CartesianPlotWith and the CartesianPlotWithout and combines them into a single plot.

 Do[
  ToExpression[
    "CombinedCartesianPlot\[VerticalLine]\[NumberSign]" <> 
   ToString[Mass] <> "\[VerticalLine]§\[VerticalLine]\[NumberSign]" <> 
   ToString[Radius] <> "\[VerticalLine]", StandardForm,
    Function[sym, 
      sym = 
    Show[ToExpression[ 
      "CartesianPlotWith\[VerticalLine]\[NumberSign]" <> 
       ToString[Mass] <> 
       "\[VerticalLine]§\[VerticalLine]\[NumberSign]" <> 
       ToString[Radius] <> "\[VerticalLine]"], 
     ToExpression[
      "CartesianPlotWithout\[VerticalLine]\[NumberSign]" <> 
       ToString[Mass] <> 
       "\[VerticalLine]§\[VerticalLine]\[NumberSign]" <> 
       ToString[Radius] <> "\[VerticalLine]"],   PlotLabel ->
  &quot;Positions of With and Without Photophoresis of a particle with \

#InsertRadiusHere#", Frame -> True], HoldAll] ], {Mass, 1, 6}, {Radius, 1, 6} ] CombinedCartesianPlot[VerticalLine][NumberSign]1[VerticalLine]§
[VerticalLine][NumberSign]1[VerticalLine]

Note: I want to color each individual curves (all 25 of them) using my own color function (ColorList) inside a plot, but I don't want each of the 6X6 (36) Plot Variables to have individual color schemes each.

Lack of Color Variation that Matches the Legend

L_R_G_2021
  • 113
  • 6
  • CombinedCartesianPlot\[VerticalLine]\[NumberSign]1\[VerticalLine]§\ \[VerticalLine]\[NumberSign]1\[VerticalLine]t CombinedCartesianPlot is nowhere defined and the syntax is wrong. And there seems to be a ppiece missing. Further it would help if you post a small example, with e.g. 2 functions. – Daniel Huber Jan 25 '22 at 17:23
  • 1
    Actually, it's fairly easy to give a short example with 25 functions, Plot[Table[k*Sin[x], {k, 25}], {x, 0, 100}] — 25 is significantly different than 2 functions and perhaps poses challenges worth addressing. Here's the concept for coloring 25 of them: Plot[Evaluate@Table[k*Sin[x], {k, 25}], {x, 0, 100}, PlotStyle -> Table[myColorFunction[k], {k, 25}]] or perhaps simply Plot[Evaluate@Table[k*Sin[x], {k, 25}], {x, 0, 100}, PlotStyle -> myColorFunction] — Related: https://mathematica.stackexchange.com/q/1731/ – Michael E2 Jan 25 '22 at 17:44
  • 2
    A more practical Q&A issue, which @Daniel kindly skirts, is that the lengthy, string-whacking approach to coding is going to put people off, especially since it's probably a simple mistake somewhere, but a mistake that may be well-hidden. Maybe it's the Evaluate thing in my previous comment and linked Q&A? – Michael E2 Jan 25 '22 at 17:52
  • Simpler version of this question here:

    https://mathematica.stackexchange.com/questions/262666/individual-coloring-of-a-list-of-plots

    – L_R_G_2021 Jan 26 '22 at 15:25

0 Answers0