1
$\begingroup$

I want to ask Mathematica to show the results of two different domains (dom1 and dom2) with different colors

dom2 = Table[3 n, {n, 10/3}];
dom1 = Array[If[FractionalPart[#/3] == 0, Nothing, #] &, 10];

f[n_] := Piecewise[{{n \[Pi], MemberQ[n]@dom1}, {1, MemberQ[n]@dom2}}]
data = Table[{n, f[n]}, {n, 1, 10}];

ListLogPlot[data, PlotRange -> Full, 
 PlotMarkers -> {"\[FilledCircle]", 6}]
$\endgroup$

2 Answers 2

3
$\begingroup$
ListLogPlot[data, 
 PlotRange -> Full, 
 Joined -> True, 
 PlotStyle -> None, 
 BaseStyle -> PointSize[Large], 
 Mesh -> {Join[Thread[{dom1, Red}], Thread[{dom2, Green}]]}]

enter image description here

Alternatively, you can wrap each point in data with Style:

styleddata = data /. {a : {Alternatives @@ dom1, _} :> Style[a, Red], 
    a : {Alternatives @@ dom2, _} :> Style[a, Green]};

ListLogPlot[styleddata, PlotRange -> Full, PlotStyle -> PointSize[Large]]

enter image description here

or separate data into two sets as in Bob Hanlon's answer:

ListLogPlot[Cases[{Alternatives @@ #, _}] @ data & /@ {dom1, dom2}, 
 PlotRange -> Full, 
 PlotStyle -> {Red, Green}, 
 BaseStyle -> PointSize[Large]]

enter image description here

$\endgroup$
2
$\begingroup$
Clear["Global`*"]

dom2 = Table[3 n, {n, 10/3}];

dom1 = Array[If[FractionalPart[#/3] == 0, Nothing, #] &, 10];

data1 = {#, # Pi} & /@ dom1;

data2 = {#, 1} & /@ dom2;

With different colors and shapes

ListLogPlot[{data1, data2}, PlotRange -> Full, PlotMarkers -> {Automatic, 8}]

enter image description here

$\endgroup$

Your Answer

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

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