Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This question already has an answer here:

I've been searching for the use of ColorFunction as an Option for ListPlot, but haven't found anything about it in the documentation. When trying the code

ListPlot[
 RandomReal[5, {10}]
 , ColorFunction -> Hue[#1, #2, 1] &
 ]

I get the error message

ListPlot::nonopt: "Options expected (instead of ColorFunction->Hue[#1,#2,1]&) beyond position 3 in ListPlot[{2.14801,2.18933,<<6>>,3.48,0.566812},ColorFunction-><<1>>&]. An option must be a rule or a list of rules."

Is it possible, and if so, how, to use ColorFunction with ListPlot? What are the arguments of the function, then?

Thanks for all help, as always!

share|improve this question

marked as duplicate by rm -rf Oct 31 '13 at 20:24

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
The problem here is that you haven't used parentheses to group the function. It should be ColorFunction -> (Hue[#, #2, 1]&). See Parentheses in pure functions: # & vs. ( # &) and Using several anonymous functions mixed together for more info. Regarding your actual question, ListPlot doesn't accept a ColorFunction without Joined -> True (or ListLinePlot). Your solution is to use either of these and convert the lines to points as in this answer –  rm -rf Oct 31 '13 at 18:47
    
Either way, it's a duplicate of one of these — you can decide which :) –  rm -rf Oct 31 '13 at 18:48
    
@rm -rf: Thanks for the link, that's great! –  Gabriel Oct 31 '13 at 19:17

1 Answer 1

up vote 2 down vote accepted

From the help:

ColorFunction requires at least one dataset to be Joined

{ListPlot[Sinc[Range[0, 10, 0.1]], ColorFunction -> Function[{x, y}, Hue[x]]],
 ListPlot[Sinc[Range[0, 10, 0.1]], ColorFunction -> Function[{x, y}, Hue[x]], Joined -> True]}

Mathematica graphics

share|improve this answer

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