7
$\begingroup$

I have the following color table:

colTable = 
  {{Black}, Table[{Blend[{Blue, Green, Yellow, Red}, x]}, {x, 1/2000, 1, 1/2000}]}; 
colTable = Flatten[colTable];

I can color a list plot curve when the plot is joined, but not the plot markers when the plot is not joined.

The following code

plot = ListPlot[coordinates*dx, 
   ColorFunction -> (Blend[colTable, #] &), Joined -> True, 
   Frame -> True, PlotRange -> {{0, 130*dx}, {0, 130*dx}}, 
   PlotStyle -> {RGBColor[0, 0, 1], Thickness[0.002]}, 
   AspectRatio -> 1, 
   FrameLabel -> {{"y in mm", ""}, {"x in mm", imageDir}}, 
   BaseStyle -> {FontWeight -> "Bold", FontSize -> 30, 
     FontFamily -> "Calibri"}, ImageSize -> 2000];

gives

enter image description here

Buy when drawing only the markers with this code

plot = ListPlot[coordinates*dx, 
   ColorFunction -> (Blend[colTable, #] &), Joined -> False, 
   Frame -> True, PlotMarkers -> Automatic, 
   PlotRange -> {{0, 130*dx}, {0, 130*dx}}, 
   PlotStyle -> {RGBColor[0, 0, 1], Thickness[0.002]}, 
   AspectRatio -> 1, 
   FrameLabel -> {{"y in mm", ""}, {"x in mm", imageDir}}, 
   BaseStyle -> {FontWeight -> "Bold", FontSize -> 30, 
     FontFamily -> "Calibri"}, ImageSize -> 2000];

I get:

enter image description here

What am I doing wrong?

With the help example from – J. M.♦ I get now the correct image below for plot markers, when using the following code:

 plot = ListPlot[MapThread[Style, {coordinates*dx, colTable}], 
   PlotStyle -> AbsolutePointSize[15], Frame -> True, 
   PlotRange -> {{0, 130*dx}, {0, 130*dx}}, AspectRatio -> 1, 
   FrameLabel -> {{"y (mm)", ""}, {"x (mm)", imageDir}}, 
   BaseStyle -> {FontWeight -> "Bold", FontSize -> 30, 
     FontFamily -> "Calibri"}, ImageSize -> 2000];

enter image description here

By the way I have used this same color table and superposed corresponding images (I did not mention that the data are center of mass coordinates of circular shaped objects in CMOS images). Here I get the following image which corresponds to the plot with the markers:

enter image description here

Question: The color table is the same for the joined data points (curve, see top plot) and for the plot markers. So I would assume for the curve at top the same color variation. But it is not the case?

$\endgroup$
  • $\begingroup$ As I see it, you're coloring by the order of the points in the latter diagram, and by their abscissas in the former diagram. I might be able to come up with something, but to help us help you, please provide at least a subset of your data. $\endgroup$ – J. M. will be back soon Oct 28 '15 at 15:08
  • $\begingroup$ I have used DumpSave and saved the variable "data" to tinyurl.com/qceeuds Thanks for looking into the data ... $\endgroup$ – mrz Oct 28 '15 at 20:33
  • $\begingroup$ Your data is unreadable for me; that may have to do with the fact that we do not have the same OS. I would suggest putting the data into something like pastebin instead. $\endgroup$ – J. M. will be back soon Oct 29 '15 at 13:43
  • $\begingroup$ Can you read that? pastebin.com/6YALzqwM $\endgroup$ – mrz Oct 29 '15 at 17:21
7
$\begingroup$

Unfortunately, as noted in the docs for ListPlot[], "ColorFunction requires at least one dataset to be Joined." One can use Style[] instead to color the points, like so:

data = Table[{x, Sin[x]}, {x, 0, π, π/11}];
cols = ColorData["ThermometerColors", "BlendArgument"];

{ListPlot[MapThread[Style, {data, cols}], Background -> Black, 
          PlotStyle -> AbsolutePointSize[4]], 
ListPlot[data, Background -> Black, ColorFunction -> (Blend[cols, #] &),
         Joined -> True, PlotStyle -> AbsoluteThickness[4]]} // GraphicsRow

joined and disconnected

$\endgroup$
  • $\begingroup$ Your solution is more than twice faster ... only one question/remark: the markers have grey sourrounding if I use white background? I used the following code: plot = ListPlot[MapThread[Style, {coordinates*dx, colTable}], PlotStyle -> AbsolutePointSize[10], Frame -> True, PlotRange -> {{0, 130*dx}, {0, 130*dx}}, AspectRatio -> 1, FrameLabel -> {{"y (mm)", ""}, {"x (mm)", imageDir}}, BaseStyle -> {FontWeight -> "Bold", FontSize -> 30, FontFamily -> "Calibri"}, ImageSize -> 2000]; $\endgroup$ – mrz Oct 28 '15 at 9:06
  • $\begingroup$ Not having your data, I can't reproduce that. What happens if you remove Background -> Black in my examples? $\endgroup$ – J. M. will be back soon Oct 28 '15 at 9:11
  • $\begingroup$ Now I tried your example data with white background and it looks good ... $\endgroup$ – mrz Oct 28 '15 at 10:07
7
$\begingroup$

Make each point a separate data set by mapping List onto the data.

n = 36;
data = Table[{x, Sin[x]}, {x, 0, π, π/n}];
colTable = {{Black}, 
    Table[{Blend[{Blue, Green, Yellow, Red}, x]}, {x, 1/n, 1, 1/n}]} // 
   Flatten;

ListPlot[List /@ data, PlotStyle -> colTable]

enter image description here

$\endgroup$
  • $\begingroup$ Great ... thanks $\endgroup$ – mrz Oct 28 '15 at 8:54
1
$\begingroup$

Perhaps:

pts = RandomReal[1, {1000, 2}];
ListPlot[pts, ColorFunction -> (Blend[colTable, #] &), Joined -> True,
   Frame -> True] /. Line[x__] :> {PointSize[0.02], Point[x]}

enter image description here

$\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.