0
$\begingroup$

Sorry for the stupid question, I am still a total beginner with Mathematica.

I have a list line plot that has some 100-1000 lines (depending on the input). I want my for loop to automatically determine which one of these lines is "important". There are roughly 3 or 4 important lines in there.

So how do I, out of, say, 100 lines which should all show up in different colors, highlight these 3-4 in bold? I don't know beforehand which ones are important -- my for loop will find out. But I cannot write use Plot Style in the standard way {Orange, Thick, Green} because I do not even know at which position the thick line should be.

Do you know what I mean? How do I generalize a position for thick when all others are also colored, but not thick?

Thanks a lot for your help!

$\endgroup$
2
  • 2
    $\begingroup$ You are not a new user on this site. Please include minimal examples of data with your questions. You have also not accepted any answers so far. Selecting an answer makes the Q/A more beneficial for page visitors. Thanks. $\endgroup$
    – Syed
    Nov 11, 2022 at 23:26
  • $\begingroup$ Yes, sorry, I have had my account for some time, but barely used it. I try to stick to the rules in future as I start to using Mathematica more. Thanks and sorry again. $\endgroup$
    – Marla
    Nov 13, 2022 at 3:32

1 Answer 1

1
$\begingroup$

I don't know beforehand which ones are important -- my for loop will find out.

You did not give MWE. I assume you want the important line be marked as say Red, and all the others Gray?
One way, is that as you build the lines, keep track in a list called importantLines, the index of the line which is important.

Then build style based on this list to make only those lines in the importantLines red, and everything else say Gray. Something like

lines = {x, 2*x, 3 + 4*x, 7*x, 2*x^2 + 5, 7 + x}
importantLines = {2, 5} (*second and fifth lines are important only*)
style = Table[If[MemberQ[importantLines, n], Red, Gray], {n, 1, Length@lines}]
Plot[lines, {x, -3, 3}, PlotStyle -> style]

Mathematica graphics

If you want the others to be dashed, you do

lines = {x, 2*x, 3 + 4*x, 7*x, 2*x^2 + 5, 7 + x}
importantLines = {2, 5} (*second and fifth lines are important only*)
style = Table[If[MemberQ[importantLines, n], Red, {Gray, Dashed}], {n, 1, Length@lines}]
Plot[lines, {x, -3, 3}, PlotStyle -> style]

Mathematica graphics

etc... You can customize the style as you want in the above. Make it thick or thin or any other allowed line style.

I am sure there are at least 9 other ways to do this.

$\endgroup$
2
  • $\begingroup$ Thanks, that was very helpful! How can I mark this answer such that it shows that this problem is solved? $\endgroup$
    – Marla
    Nov 13, 2022 at 3:34
  • $\begingroup$ @Marla to accept an answer at stackexchange, you just click on the little green check/arrow near the top left edge of the answer which you want to accept. You can just look at any accepted answer on this site to see this check marker. $\endgroup$
    – Nasser
    Nov 13, 2022 at 3:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.