Question: Extend/Truncate list of Colours to plot

I need to automatically extend or truncate a colour list to suit number of points in plottools:-point plot.
extending the list the colour sequence could be repeated or if the is too awkard just add black.
I can't figure out how to select the list of colours to put into a new list to modify.

This will be inside a plotting procedure.

restart

with(ListTools)

[BinaryPlace, BinarySearch, Categorize, Classify, Collect, Deal, DotProduct, Enumerate, FindMaximalElement, FindMinimalElement, FindRepetitions, Flatten, FlattenOnce, Group, Interleave, InversePermutation, Join, JoinSequence, LengthSplit, MakeUnique, Occurrences, Pad, PartialSums, Reverse, Rotate, Search, SearchAll, SelectFirst, SelectLast, Slice, Sorted, Split, Transpose, Unpermute]

(1)

L:=[[1,2],[3,4],[-5,6],[-3,-2]]

[[1, 2], [3, 4], [-5, 6], [-3, -2]]

(2)

qty:=nops(L)

4

(3)

styles:=[symbol=solidcircle,colour=[red,green,blue,orange],symbolsize=12]

[symbol = solidcircle, colour = [red, green, blue, orange], symbolsize = 12]

(4)

 

plots:-display(plottools:-point(L,styles[]))

 

#Need to extend or truncate the list of colours to match the number of points
#styles can be copied to styles 1,2 etc
#the extended list would be a repeatition of the colour sequence given
#would need to look for color or colour;

has(styles,colour); #how to select colour our into a seperate list?

true

(5)

#too few point for the colours;
L1:=[[1,2],[3,4],[-5,6]]

[[1, 2], [3, 4], [-5, 6]]

(6)

plots:-display(plottools:-point(L1,styles[]))

Error, (in Plot:-Structure:-Points) number of colors must match number of points

 

#too many point for the colours;
L2:=[[1,2],[3,4],[-5,6],[-3,-2],[6-1],[0,1]]

[[1, 2], [3, 4], [-5, 6], [-3, -2], [5], [0, 1]]

(7)

plots:-display(plottools:-point(L2,styles[]))

Error, (in plottools:-point) incorrect arguments for creating points structure, try providing the dimension option

 
 

 

Download 2024-09-06_Q_Extend_or_Truncate_List_of_Colours.mw

Please Wait...