3
$\begingroup$

I have a big sorted list and some of it is important, I want to visualize the position of these important elements.

RandomSeed[1234];
red = RandomInteger[10000, 100];(*important elements*)
point = Sort@RandomInteger[10000, 1000];(*all elements*)
pointColor = If[MemberQ[red, #], Style[#, Red], #] & /@ point;
ListPlot[pointColor]

enter image description here

I try some ways fails such as

  • ListPlot[pointColor, PlotStyle -> RGBColor[0, 0, 1, 0.04]]
  • pointColor = If[MemberQ[red, #], Style[#, Red, Thick], #] & /@ point; ListPlot[pointColor]

but only this code:

ListPlot[pointColor, PlotStyle -> Blue] /. 
 RGBColor[0, 0, 1] -> RGBColor[0, 0, 1, 0.04]

enter image description here

So what the better way to visualize these important elements?

$\endgroup$
3
$\begingroup$
pointColor = If[MemberQ[red, #], Style[#, Opacity[1, Red], PointSize[Medium]], #]& /@ point;

ListPlot[pointColor, PlotStyle -> RGBColor[0, 0, 1, 0.04]]

enter image description here

$\endgroup$
2
$\begingroup$

A bit of a workaround, but if you don't have to generate random numbers and you already have the correct lists it would work better than trying to apply a sort of mask/style to one list: keeping the two lists separate before plotting is probably easier. You could also remove the important elements from the total list if you don't want to double plot them.

Position[point, #] & /@ red;
pos = Flatten[Select[%, UnsameQ[#, {}] &]];

important = Transpose[{pos, point[[pos]]}];

Show[
 ListPlot[point],
 ListPlot[important, PlotStyle -> Red]
 ]

enter image description here

$\endgroup$
1
$\begingroup$
RandomSeed[1234];
red = AssociationThread[RandomInteger[10000, 100] -> True];
point = Sort@RandomInteger[10000, 1000];

Get the positions pos1 of important points:

pos1 = Pick[Range[Length[point]], Lookup[red, point, False]];
pos2 = Complement[Range[Length[point]], pos1];

Put the important points last in Show to get them on top of the other points:

Show[
 ListPlot[Thread[{pos2, point[[pos2]]}], PlotStyle -> Directive[Black, PointSize[Small]]],
 ListPlot[Thread[{pos1, point[[pos1]]}], PlotStyle -> Directive[Red, PointSize[Large]]]]

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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