how to Coloring the data points in a scatter plot

kam leo

New Member
Joined
Apr 21, 2016
Messages
15
hello again , i have some number data set (below), i would like to plot with different color, say,

1 ,2, 3, 4, 5, 6= red; 7, 8, 9, 10, 11,12 =blue, 13, 14, 15, 16, 17,18=black; .....5=green.....

Code:
[TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]3[/TD]
[/TR]
[TR]
[TD="align: right"]8[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[/TR]
[TR]
[TD="align: right"]16[/TD]
[/TR]
[TR]
[TD="align: right"]17[/TD]
[/TR]
[TR]
[TD="align: right"]38[/TD]
[/TR]
[TR]
[TD="align: right"]35[/TD]
[/TR]
[TR]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD="align: right"]6[/TD]
[/TR]
[TR]
[TD="align: right"]19[/TD]
[/TR]
[TR]
[TD="align: right"]26[/TD]
[/TR]
[TR]
[TD="align: right"]28[/TD]
[/TR]
</tbody>[/TABLE]
........ and more
.....:confused::confused::beerchug: Any help you can provide will be greatly appreciated!! thanks!!!!
 
It looks like you want to set a different color for each set of six data points. If so, select the chart, and then try...

Code:
[COLOR=darkblue]Option[/COLOR] [COLOR=darkblue]Explicit[/COLOR]

[COLOR=darkblue]Sub[/COLOR] ColorDataPoints()

    [COLOR=darkblue]Dim[/COLOR] vColors [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Variant[/COLOR]
    [COLOR=darkblue]Dim[/COLOR] lPntIndx [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR]
    
    [COLOR=darkblue]If[/COLOR] ActiveChart [COLOR=darkblue]Is[/COLOR] [COLOR=darkblue]Nothing[/COLOR] [COLOR=darkblue]Then[/COLOR]
        MsgBox "Select a chart, and try again.", vbExclamation
        [COLOR=darkblue]Exit[/COLOR] [COLOR=darkblue]Sub[/COLOR]
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
    
    vColors = Array(RGB(255, 0, 0), RGB(0, 112, 192), RGB(0, 0, 0)) [COLOR=green]'red, blue, and black (add more colors as necessary)[/COLOR]
    
    [COLOR=darkblue]With[/COLOR] ActiveChart.SeriesCollection(1)
        [COLOR=darkblue]For[/COLOR] lPntIndx = 1 [COLOR=darkblue]To[/COLOR] .Points.Count
            [COLOR=darkblue]If[/COLOR] lPntIndx > (UBound(vColors) + 1) * 6 [COLOR=darkblue]Then[/COLOR] [COLOR=darkblue]Exit[/COLOR] [COLOR=darkblue]For[/COLOR]
            .Points(lPntIndx).Format.Fill.ForeColor.RGB = vColors(Int((lPntIndx - 1) / 6))
        [COLOR=darkblue]Next[/COLOR] lPntIndx
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]
    
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]

Note that the RGB function is used to specify the color. You can add more colors as necessary.

Hope this helps!
 
Last edited:
Upvote 0
hello Domenic,
data are in one column, not six number each set. six number is what i want to assign them to different color.
for example: if the number from column A is 1 ,2, 3, 4, 5, 6, then assign their Data Points to red color; if the number from column A is 7, 8, 9, 10, 11,12 then assign their Data Points to blue color.. ..and so on. thanks!
 
Upvote 0
You'll need to change the If...Then...Else statement accordingly...

Code:
[color=darkblue]Option[/color] [color=darkblue]Explicit[/color]

[color=darkblue]Sub[/color] ColorDataPoints()

    [color=darkblue]Dim[/color] sYValsAddr [color=darkblue]As[/color] [color=darkblue]String[/color]
    [color=darkblue]Dim[/color] lPntIndx [color=darkblue]As[/color] [color=darkblue]Long[/color]
    [color=darkblue]Dim[/color] YVal [color=darkblue]As[/color] [color=darkblue]Double[/color]
    [color=darkblue]Dim[/color] lColor [color=darkblue]As[/color] [color=darkblue]Long[/color]
    
    [color=darkblue]If[/color] ActiveChart [color=darkblue]Is[/color] [color=darkblue]Nothing[/color] [color=darkblue]Then[/color]
        MsgBox "Select a chart, and try again.", vbExclamation
        [color=darkblue]Exit[/color] [color=darkblue]Sub[/color]
    [color=darkblue]End[/color] [color=darkblue]If[/color]
    
    [color=darkblue]With[/color] ActiveChart.SeriesCollection(1)
        sYValsAddr = Split(.Formula, ",")(2)
        For lPntIndx = 1 [color=darkblue]To[/color] .Points.Count
            YVal = Range(sYValsAddr).Cells(lPntIndx).Value
            [color=darkblue]If[/color] YVal >= 13 [color=darkblue]Then[/color]
                lColor = RGB(0, 0, 0) [color=green]'black[/color]
            [color=darkblue]ElseIf[/color] YVal >= 7 [color=darkblue]Then[/color]
                lColor = RGB(0, 112, 192) [color=green]'blue[/color]
            [color=darkblue]Else[/color]
                lColor = RGB(255, 0, 0) [color=green]'red[/color]
            [color=darkblue]End[/color] [color=darkblue]If[/color]
            .Points(lPntIndx).Format.Fill.ForeColor.RGB = lColor
        [color=darkblue]Next[/color] lPntIndx
    [color=darkblue]End[/color] [color=darkblue]With[/color]
    
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top