# How to change the colour of a single line in a graph

Basically i want to change the colour of a single line or 'band' in a ListLinePlot. The first image is the graph i have and the second is the format i'm trying to put the minimum and maximum negative lines in. Thanks in advance

Edit - My code:

zigzaghamiltonian[n_, k_, t2_, phi_, delta_] := Table[
If[Mod[u, 2] != 0 && v == (u + 1), -2*Cos[k/2],
If[Mod[u, 2] == 0 && v == (u - 1), -2*Cos[k/2],
If[Mod[u + v - 1, 4] == 0 && Abs[u - v] < 2, -1,
If[
Mod[u, 2] != 0 && (v == (u + 2) || v == (u - 2)), -t2*2*
Cos[phi + k/2],
If[
Mod[u, 2] == 0 && (v == (u + 2) || v == (u - 2)), -t2*2*
Cos[k/2 - phi],
If[Mod[u, 2] != 0 && u == v, -t2*2*Cos[phi + k] + delta,
If[Mod[u, 2] == 0 && u == v, -t2*2*Cos[k - phi] - delta,
0]]]]]]],
{u, 2*n}, {v, 2*n}];
vx[n_, k_, t2_, phi_] := Table[
If[Mod[u, 2] != 0 && v == (u + 1), -Sin[k/2],
If[Mod[u, 2] == 0 && v == (u - 1), Sin[k/2],
If[Mod[u, 2] != 0 && v == (u + 2), -t2*Sin[k/2]*Exp[-I*phi],
If[Mod[u, 2] == 0 && v == (u + 2), -t2*Sin[k/2]*Exp[I*phi],
If[Mod[u, 2] != 0 && v == (u - 2), -t2*Sin[k/2]*Exp[I*phi],
If[Mod[u, 2] == 0 && v == (u - 2), -t2*Sin[k/2]*Exp[-I*phi],
If[Mod[u, 2] != 0 && u == v, -t2*2*Sin[phi + k],
If[Mod[u, 2] == 0 && u == v, -t2*2*Sin[k - phi], 0]]]]]]]],
{u, 2*n}, {v, 2*n}];
oka[n_] :=
Table[If[Mod[u, 2] != 0 && v == u, 1, 0], {v, 2*n}, {u, 2*n}];
okb[n_] :=
Table[If[Mod[u, 2] == 0 && v == u, 1, 0], {v, 2*n}, {u, 2*n}];

nvalue = 15;
k = Range[0, 2*Pi, 2*Pi/99];
delta = 0.0;
phi = Pi/2;
t2 = 0.00;
eigvals =
Table[N[
Re[Sort[
Eigenvalues[
zigzaghamiltonian[nvalue, k[[i]], t2, phi, delta]]]]], {i,
100}] ;

ListLinePlot[
Transpose[
Table[{k[[i]], eigvals[[i]][[j]]}, {i, 0, 100}, {j, 0, 2*nvalue}]],
PlotStyle -> Blue]

• Be careful here: {i, 0, 100}, {j, 0, 2*nvalue} Mathematica indexes from 1, not 0. Element 0 is the head e.g {1, 2, 3}[[0]] returns List. You'll get a Part error when you index k or eigvals otherwise. Commented Dec 11, 2021 at 12:48

Your code produces a slightly different plot than the one shown in the question. This seems to do what is desired on the graph generated:

ListLinePlot[
Transpose[
Table[{k[[i]], eigvals[[i, j]]}, {i, 1, 100}, {j, 1, 2*nvalue}]],
PlotStyle ->    (* N.B. *)
ReplacePart[   (* if you know the indices... *)
ConstantArray[Blue, 2*nvalue],
{nvalue -> Red, nvalue + 1 -> Red}]
]


• If you don't know the indices: ListLinePlot[ Transpose[ Table[{k[[i]], eigvals[[i, j]]}, {i, 1, 100}, {j, 1, 2*nvalue}]], PlotStyle -> ReplacePart[ ConstantArray[Blue, 2*nvalue], Position[#, Alternatives @@ MinMax[#]] &[1/eigvals[[1]]] -> Red]] -- 1/eigvals works in this case because the eigenvalues are separated by zero. Commented Dec 11, 2021 at 15:21

You may give a separate style to every curve.

Here is a simple example:

funs = Table[Sin[x] + i, {i, 4}];
styles = Table[Blue, 4];
styles[[3]] = Red;
Plot[funs, {x, 0, 4 Pi}, PlotStyle -> styles]


nvalue = 15;

table = Transpose[Table[{k[[i]], eigvals[[i]][[j]]}, {i, 1, 100}, {j, 1, 2 nvalue}]];

ListLinePlot[table,
PlotStyle -> ArrayPad[{Red, Red}, nvalue - 1, Blue]]


If the indices of the lines you want to color red is not known, as in

shuffledtable = RandomSample[table];


and you want to color the two lines closest to the horizontal axis red, you can:

1. Sort shuffledtable by the second coordinates of the first points:
ListLinePlot[SortBy[#[[1, -1]] &] @ shuffledtable,
PlotStyle -> ArrayPad[{Red, Red}, nvalue - 1, Blue]]


1. Alternatively, you can use Nearest to identify the two lists nearest the horizontal axis:
shuffledtablestyled = MapAt[Style[#, Red] &, shuffledtable,
List /@ Nearest[shuffledtable[[All, 1, 2]] -> "Index", 0, 2]];

ListLinePlot[shuffledtablestyled, PlotStyle -> Blue]


For completeness, here is a manual post-processing approach:

During this animation, I use only Simple Click, Double Click and copy-paste.
The double-click is for selecting the Line interactively.

The two pieces of code that you may not time to read :
theLine = Cases[, Line[___], Infinity]

/. theLine -> {Red, Dashed, AbsoluteThickness[3], theLine}

llp =  ListLinePlot[table, PlotStyle -> Blue, ImageSize -> Large];


Interactively change line colors flipping between Blue and Red using FlipView:

styles = {Directive[Thick, Opacity[1], Blue], Directive[Thick, Opacity[1], Red]};

llp /. l_Line :>