Plot Coloring by Values
Coloring by Value
plotcommand(plotargs, colorscheme=["valuesplit", V, mapping, opts])
arguments to a plotting command
(optional) rtable or list of values
(optional) list specifying mapping of values to colors
(optional) optional arguments as described in the following Options section.
Use the colorscheme option to color a plot by values.
dataplot(LinearAlgebra:-RandomVector(50), style=point, colorscheme=["valuesplit", [-infinity..-51="Blue", -50..50="DarkGreen", 51..infinity="DarkRed"]]);
This page describes how to color a plot by values using the "valuesplit" scheme with the colorscheme option, which is available for most plotting commands. Specifically, the points in a plot element are partitioned and colors are assigned to each group of points based on the associated values or the plot data itself. This color scheme can be applied to a surface, a curve, or a set of points created by a plot command.
For general information about the colorscheme option and a list of other color schemes available, see the plot/colorscheme help page.
In the description below, the word "points" is used throughout to include surfaces and curves, in addition to collections of points, referring to the data points that define these structures. A full description of the colors that can be used with plots is available on the plot/color help page.
The "valuesplit" color scheme allows you to partition the points by color according to associated values. The syntax of the option is colorscheme=["valuesplit", V, mapping], where V and mapping are optional. If mapping is given, it must be in the form of a list or procedure.
V is an rtable or list with n elements, where n is the number of points in the plot structure that is being colored. V can contain numerical values, names, or strings. The i-th value of V corresponds to the i-th entry of the plot data. V need not have the same dimension as the plot data. For example, if the plot is a surface constructed from an m by n grid of points, then V can be an m by n Matrix or an m⁢n Vector with the i−1⁢n+j-th value associated with the i,j-th point.
If V is not provided, then the plot data itself is used. The values are taken to be the y-coordinates of the data points for 2-D plots and the z-coordinates for 3-D plots.
The most common form of mapping is a list of equalities specifying the mapping of values in V to colors. If the mapping option is not supplied, a suitable color mapping for each of the distinct elements of V is automatically created with colors chosen from the current default color palette. (See the plot/color help page for more information about default colors for plots.)
For an entry s=t in the mapping list, the color t can be specified in any of the ways described on the plot/color help page. In addition to being any of the values available in V, s can also be a set or list of such values or a numerical range. For example, 3.5..5.8="Green" means that all points associated with values in V from 3.5 to 5.8 will be colored green.
Optionally, the mapping list can contain a single color as the final element; this specifies the default color, which is otherwise set to black. For example, [1="Blue", 2="Red", "Yellow"] means that all points associated with value 1 will be colored blue, those associated with value 2 will be colored red, and any remaining points will be colored yellow.
When a value w in V is checked against a mapping list, it is compared to each s=t entry until there is a match or the list is exhausted. Thus, if there are two or more possible matches, the first in the list is used. The comparison is done using evalb, so values such as 4 and 4.0 are considered equivalent.
The mapping argument can also be a user-provided procedure that takes a single value as input and returns a color. This would allow you to specify more complicated conditions or distinguish integer and float values.
Setting this option applies the procedure f to every data point before it is colored. For example, setting transformdata=ln with an exponential data set causes the data to be colored evenly, rather than having it skewed to the lower end of the color gradient.
Color a matrix of points by a given set of values:
data ≔ Matrix⁡Statistics:-Sample⁡Uniform⁡0,1,50,2|LinearAlgebra:-RandomVector⁡50,generator=rand⁡0..3:
If no argument is supplied for the mapping argument, then colors from the default color palette are used:
Values can be strings or names, in addition to numbers.
V1 ≔ Vector⁡4,5,7,6,3,2,2,4,6,5:
V2 ≔ Vector⁡iris,rose,daffodil,iris,rose,daffodil,iris,iris,rose,weed:
In this example, the absolute value function is applied to the data before it is colored.
The "valuesplit" option can be applied to surfaces and curves, as well as points. The following command uses the z-coordinate values to determine the color of the surface.
The following example shows how a custom procedure can be used with the "valuesplit" color scheme. The plot shows pitcher Dave Stieb's Earned Run Average (ERA) over the years 1979-1993. (Source: www.databasebaseball.com.) Green points indicate the years in which Stieb had more wins than losses, while the lighter colors indicate the years in which he started in fewer than 15 games.
Games ≔ Vector⁡18,32,25,38,36,35,36,34,31,31,33,33,9,14,4:
Year ≔ Vector⁡seq⁡i,i=1979..1993:
Wins ≔ Vector⁡8,12,11,17,17,16,14,7,13,16,17,18,4,4,1:
Losses ≔ Vector⁡8,15,10,14,12,8,13,12,9,8,8,6,3,6,3:
ERA ≔ Vector⁡4.31,3.71,3.19,3.25,3.04,2.83,2.48,4.74,4.09,3.04,3.35,2.93,3.17,5.04,6.04,datatype=float8:
DF ≔ DataFrame⁡Games|Wins|Losses|ERA,columns=Games,Wins,Losses,ERA,rows=Year
p := proc(i)
if Games[i]>15 then
return `if`(Wins[i]>Losses[i], "DarkGreen", "DarkRed");
return `if`(Wins[i]>Losses[i], "LightGreen", "RosyBrown");
dataplot⁡Year,ERA,view=1978..1994,0..7,style=point,symbolsize=20,colorscheme=valuesplit,Vector⁡15,i→i,p,labels=Year,ERA,title=ERA for Dave Stieb
The colorscheme/valuesplit option was introduced in Maple 2016.
For more information on Maple 2016 changes, see Updates in Maple 2016.
Download Help Document
What kind of issue would you like to report? (Optional)