Plot Coloring by Values - Maple Help

Home : Support : Online Help : Graphics : 2-D : Options : colorscheme : Plot Coloring by Values

Plot Coloring by Values

 Calling Sequence plotcommand(plotargs, colorscheme=["valuesplit", V, mapping, opts])

Parameters

 plotargs - arguments to a plotting command V - (optional) rtable or list of values mapping - (optional) list specifying mapping of values to colors opts - (optional) optional arguments as described in the following Options section.

Summary

 • 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"]]);

Introduction

 • 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.

Coloring by Value

 • 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 $mn$ Vector with the $\left(i-1\right)n+j$-th value associated with the $\left(i,j\right)$-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.

Options

 • transformdata=f
 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.

Examples

Color a matrix of points by a given set of values:

 > $\mathrm{data}≔\mathrm{Matrix}\left(⟨⟨\mathrm{Statistics}:-\mathrm{Sample}\left(\mathrm{Uniform}\left(0,1\right),\left[50,2\right]\right)⟩|\mathrm{LinearAlgebra}:-\mathrm{RandomVector}\left(50,\mathrm{generator}=\mathrm{rand}\left(0..3\right)\right)⟩\right):$
 > $\mathrm{plots}:-\mathrm{pointplot}\left(\mathrm{data}\left[..,1\right],\mathrm{data}\left[..,2\right],\mathrm{symbolsize}=20,\mathrm{symbol}=\mathrm{solidbox},\mathrm{colorscheme}=\left["valuesplit",\mathrm{data}\left[..,3\right],\left[0="Red",1="Blue",2="Green",3="Purple"\right]\right]\right)$

If no argument is supplied for the mapping argument, then colors from the default color palette are used:

 > $\mathrm{plots}:-\mathrm{pointplot}\left(\mathrm{data}\left[..,1\right],\mathrm{data}\left[..,2\right],\mathrm{symbolsize}=20,\mathrm{symbol}=\mathrm{solidbox},\mathrm{colorscheme}=\left["valuesplit",\mathrm{data}\left[..,3\right]\right]\right)$

Values can be strings or names, in addition to numbers.

 > $\mathrm{V1}≔\mathrm{Vector}\left(\left[4,5,7,6,3,2,2,4,6,5\right]\right):$
 > $\mathrm{V2}≔\mathrm{Vector}\left(\left["iris","rose","daffodil","iris","rose","daffodil","iris","iris","rose","weed"\right]\right):$
 > $\mathrm{dataplot}\left(\mathrm{V1},\mathrm{colorscheme}=\left["valuesplit",\mathrm{V2},\left["iris"="Indigo","rose"="HotPink","daffodil"="Gold","OliveDrab"\right]\right],\mathrm{style}=\mathrm{point},\mathrm{symbolsize}=20,\mathrm{view}=\left[0..10,0..10\right]\right)$

In this example, the absolute value function is applied to the data before it is colored.

 > $\mathrm{dataplot}\left(\mathrm{LinearAlgebra}:-\mathrm{RandomVector}\left(50\right),\mathrm{style}=\mathrm{point},\mathrm{colorscheme}=\left["valuesplit",\left[0..30="Blue",30..60="Red",60..\mathrm{\infty }="Green"\right],\mathrm{transformdata}=\mathrm{abs}\right]\right)$

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.

 > $\mathrm{plot3d}\left(\left[y\mathrm{cos}\left(x\right),y\mathrm{sin}\left(x\right),y\right],x=0..2\mathrm{\pi },y=0..1,\mathrm{colorscheme}=\left["valuesplit",\left[0..0.3="NavyBlue",0.3..0.7="RoyalBlue",0.7..1.0="LightBlue"\right]\right]\right)$

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.

 > $\mathrm{Games}≔\mathrm{Vector}\left(\left[18,32,25,38,36,35,36,34,31,31,33,33,9,14,4\right]\right):$
 > $\mathrm{Year}≔\mathrm{Vector}\left(\left[\mathrm{seq}\left(i,i=1979..1993\right)\right]\right):$
 > $\mathrm{Wins}≔\mathrm{Vector}\left(\left[8,12,11,17,17,16,14,7,13,16,17,18,4,4,1\right]\right):$
 > $\mathrm{Losses}≔\mathrm{Vector}\left(\left[8,15,10,14,12,8,13,12,9,8,8,6,3,6,3\right]\right):$
 > $\mathrm{ERA}≔\mathrm{Vector}\left(\left[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\right],\mathrm{datatype}=\mathrm{float}\left[8\right]\right):$
 > $\mathrm{DF}≔\mathrm{DataFrame}\left(⟨\mathrm{Games}|\mathrm{Wins}|\mathrm{Losses}|\mathrm{ERA}⟩,\mathrm{columns}=\left["Games","Wins","Losses","ERA"\right],\mathrm{rows}=\mathrm{Year}\right)$
 ${\mathrm{DF}}{≔}\begin{array}{c}\left[\begin{array}{ccccc}{}& {"Games"}& {"Wins"}& {"Losses"}& {"ERA"}\\ {1979}& {18}& {8}& {8}& {4.31000000000000}\\ {1980}& {32}& {12}& {15}& {3.71000000000000}\\ {1981}& {25}& {11}& {10}& {3.19000000000000}\\ {1982}& {38}& {17}& {14}& {3.25000000000000}\\ {1983}& {36}& {17}& {12}& {3.04000000000000}\\ {1984}& {35}& {16}& {8}& {2.83000000000000}\\ {1985}& {36}& {14}& {13}& {2.48000000000000}\\ {1986}& {34}& {7}& {12}& {4.74000000000000}\\ {1987}& {31}& {13}& {9}& {4.09000000000000}\\ {1988}& {31}& {16}& {8}& {3.04000000000000}\\ {⋮}& {⋮}& {⋮}& {⋮}& {⋮}\end{array}\right]\\ \hfill {\text{15 x 4 DataFrame}}\end{array}$ (1)
 > p := proc(i)    if Games[i]>15 then        return if(Wins[i]>Losses[i], "DarkGreen", "DarkRed");    else        return if(Wins[i]>Losses[i], "LightGreen", "RosyBrown");    end if;  end proc:
 > $\mathrm{dataplot}\left(\mathrm{Year},\mathrm{ERA},\mathrm{view}=\left[1978..1994,0..7\right],\mathrm{style}=\mathrm{point},\mathrm{symbolsize}=20,\mathrm{colorscheme}=\left["valuesplit",\mathrm{Vector}\left(15,i↦i\right),p\right],\mathrm{labels}=\left["Year","ERA"\right],\mathrm{title}="ERA for Dave Stieb"\right)$

Compatibility

 • The colorscheme/valuesplit option was introduced in Maple 2016.