1

Considering

dacount = {{0, 69}, {1, 122}, {2, 98}, {3, 122}, {4, 69}}

ListPlot[dacount, AxesOrigin -> {-1, 0}, 
         PlotMarkers ->Automatic
         PlotStyle-> Lighter[Red, #] & /@ Range[0.5, 1, 0.1],
         Filling -> Axis, FillingStyle -> Opacity[0.8], 
         PlotRange -> {{-1, 4.5}, {0, 192}}]

enter image description here

My hope there was for each point to take a different shade of red. But I can`t understand how to have a style for point which I tried to set as different list.

2 Answers 2

6

In your original code, the PlotStyle option won't affect the marker symbols, so you can leave it out. Instead, change your PlotMarkers option to the following:

PlotMarkers ->  With[{markerSize =  0.04}, 
 {Graphics[{Lighter[Red, #], Disk[]}], markerSize} & /@ Range[0.5, 1, 0.1]]

This will not yet have the desired effect until you replace the list dacount by:

Map[List, dacount]

By increasing the depth of the point list in this way, each point is assigned a marker style of its own from the list in PlotMarkers. So the final code is:

ListPlot[Map[List, dacount], AxesOrigin -> {-1, 0}, 
 PlotMarkers -> 
  With[{markerSize = 
     0.04}, {Graphics[{Lighter[Red, #], Disk[]}], markerSize} & /@ 
    Range[0.5, 1, 0.1]], Filling -> Axis, 
 FillingStyle -> Opacity[0.8], PlotRange -> {{-1, 4.5}, {0, 192}}]

enter image description here

1
  • Strictly speaking, in the original code the PlotStyle option does affect the marker symbols but is not specified correctly. Try ListPlot[List/@dacount,AxesOrigin->{-1,0},PlotMarkers->{{\[FilledCircle],12}},PlotStyle->(Lighter[Red,#]&/@Range[0.5,1,0.1]),Filling->Axis,FillingStyle->Opacity[0.8],PlotRange->{{-1,4.5},{0,192}}]. Nov 6, 2011 at 9:10
1

You can also do it the following way:

xMax = Max@dacount[[All, 1]];
Show@(ListPlot[{#}, AxesOrigin -> {-1, 0}, PlotMarkers -> Automatic, 
     PlotStyle -> (RGBColor[{(#[[1]] + 5)/(xMax + 5), 0, 0}]), 
     Filling -> Axis, FillingStyle -> Opacity[0.8], 
     PlotRange -> {{-1, 4.5}, {0, 192}}] & /@ dacount)

enter image description here

This plots each point in dacount individually and assigns it a shade of red depending on the x value. The plots are then combined with Show.

I've arbitrarily chosen a scaling and offset for the different shades. You can choose whatever you want, as long as you ensure that the max value is 1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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