How to highlight or color certain values in a list based on position.. For example x = {1,2,3,4,5,5,5,6}... I want to plot x and highlight values (Red) in a position such as {0,4,5} and others should be black. I want something like highlightedX={1,2,3,4,5,5,5,6}.. Thank you


A straightforward solution is to use MapAt combined with Style. Given your data and a modified highlightpositions (lists in Wolfram are indexed 1 to n)

highlightPositions = {1, 5, 6};

MapAt[Style[#, FontColor -> Red] &, x, {#} & /@ highlightPositions]

enter image description here


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.