wolfram mathematica - ListPlot: individual point colors -


i've got simple listplot like

list2 = table[{x, sqrt[x]}, {x, 0, 100}]; 

now want color specific points red, every 5th point, tried

mycolor[x_] /; mod[x, 5] == 0 = red; mycolor[_] = blue; 

now

listplot[#, plotstyle -> absolutepointsize[3], colorfunction ->  mycolor[#[[all, 1]], colorfunctionscaling -> false]] &[list2] 

doesnt work quite right, points still blue. wrong here?

thanks, archi

here easy way result you're after :-

list2 = table[{x, sqrt[x]}, {x, 0, 100}]; mycolor[x_] := if[mod[x, 5] == 0, red, blue]; mycolors = mycolor /@ list2[[all, 1]]; listplot[list /@ list2,  plotstyle -> map[{absolutepointsize[3], #} &, mycolors]] 

enter image description here

alternatively, colour function, rm -rf's answer on george's link :-

list2 = table[{x, sqrt[x]}, {x, 0, 100}]; mycolor = function[{x, y}, if[mod[x, 5] == 0, red, blue]]; listlineplot[list2,   plotstyle -> absolutepointsize[3], colorfunction -> mycolor,    colorfunctionscaling -> false] /. line -> point 

further comment

for different plot markers have reverted easy method. in order apply different styles , plot markers in listplot differently styled points have in separate lists, hence list /@ list2. (only 2 lists necessary though.)

clear[mycolor]; list2 = table[{x, sqrt[x]}, {x, 0, 100}]; mycolor[x_] := if[mod[x, 5] == 0,    {red, "\[filleduptriangle]", 14},    {blue, "\[filledsmallcircle]", 6}]; mycolorspec = mycolor /@ first /@ list2; listplot[list /@ list2,  plotmarkers -> apply[style[#2, fontsize -> #3, #1] &,    mycolorspec, {1}]] 

enter image description here


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -