Raster[{{a11,a12,…},…}]
is a two-dimensional graphics primitive which represents a rectangular array of gray cells.
Raster[{{{r11,g11,b11},…},…}]
represents an array of RGB color cells.
Raster[{{{r11,g11,b11,α11},…},…}]
represents an array of color cells with opacity αij.
Raster[{{{a11,α11},…},…}]
represents an array of gray cells with the specified opacities.
Raster
Raster[{{a11,a12,…},…}]
is a two-dimensional graphics primitive which represents a rectangular array of gray cells.
Raster[{{{r11,g11,b11},…},…}]
represents an array of RGB color cells.
Raster[{{{r11,g11,b11,α11},…},…}]
represents an array of color cells with opacity αij.
Raster[{{{a11,α11},…},…}]
represents an array of gray cells with the specified opacities.
Details and Options
- Raster[array,ColorFunction->f] specifies that each cell should be colored using the graphics directives obtained by applying the function f to the value specified for that cell.
- If array has dimensions {n,m}, then Raster[array] is assumed to occupy the rectangle Rectangle[{0,0},{m,n}]. »
- Raster[array,{{xmin,ymin},{xmax,ymax}}] specifies that the raster should be taken instead to fill the rectangle Rectangle[{xmin,ymin},{xmax,ymax}]. »
- Scaled and Offset can be used to specify the coordinates for the rectangle.
- Raster[array,Automatic] is equivalent to Raster[array,{{0,0},{m,n}}].
- Raster[array,rect,{amin,amax}] specifies that cell values should be scaled so that amin corresponds to 0 and amax corresponds to 1. Cell values outside this range are clipped to be 0 or 1.
- array can be a SparseArray object.
- Image[Raster[…]] converts a Raster object to an image.
Examples
open all close allBasic Examples (4)
Rectangular array of gray cells:
Graphics[Raster[{{0, 0.2, 0.4}, {0.6, 0.8, 1}}]]Graphics[Raster[{{{0, 1, 1}, {1, 0, 1}, {1, 1, 0}}, {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}}]]Array of gray cells with opacity:
Graphics[{{Red, Disk[{5, 5}, 4]}, Raster[Table[{1 - x, y}, {x, .1, 1, .1}, {y, .1, 1, .1}]]}]Array of RGB cells with opacity:
Graphics[{{Red, Disk[{5, 5}, 4]}, Raster[Table[{x, y, x, y}, {x, .1, 1, .1}, {y, .1, 1, .1}]]}]Scope (14)
Raster Specification (3)
For an
×
matrix, the raster occupies the rectangle {0,0} to {m,n}:
a = {{0, 0.2, 0.4}, {0.6, 0.8, 1}};Graphics[Raster[a], Frame -> True, FrameTicks -> False]Specify the shape of the raster explicitly, using ordinary coordinates:
Graphics[Raster[a, {{0, 1}, {5, 4}}], PlotRange -> {{0, 5}, {0, 5}}, Frame -> True]Use Scaled and ImageScaled:
a = {{0, 0.2, 0.4}, {0.6, 0.8, 1}};Graphics[Raster[a, {Scaled[{0, .3}], Scaled[{1, .7}]}], PlotRange -> {{0, 5}, {0, 5}},
Frame -> True]Graphics[Raster[a, {ImageScaled[{0, .3}], ImageScaled[{1, .7}]}], PlotRange -> {{0, 5}, {0, 5}},
Frame -> True]Use Offset:
a = {{0, 0.2, 0.4}, {0.6, 0.8, 1}};Graphics[Raster[a, {Offset[{10, 10}, {0, 0}], Offset[{-10, -10}, {5, 5}]}], PlotRange -> {{0, 5}, {0, 5}},
Frame -> True]Raster Styling (11)
A raster of a scalar matrix uses gray level by default:
a = {{0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1}};Graphics[Raster[a], Frame -> True, FrameTicks -> False]Graphics[Raster[a, ColorFunction -> GrayLevel], Frame -> True, FrameTicks -> False]The values outside the range 0 to 1 are normally clipped to be 0 or 1:
a = {{-0.4, -0.2, 0, 0.2, 0.4, 0.5, 0.6, 0.8, 1, 1.2, 1.4}};Graphics[Raster[a], Frame -> True, FrameTicks -> False]a = {{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};Graphics[Raster[a, Automatic, {0, 10}], Frame -> True, FrameTicks -> False]The values outside the specified range are clipped:
a = {{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};Graphics[Raster[a, Automatic, {2, 8}], Frame -> True, FrameTicks -> False]An array of pairs of numbers is treated as a gray level with opacity:
a = {{{0, .2}, {0, .4}, {0, .5}, {0, .6}, {0, .8}, {0, 1}}};Graphics[Raster[a], Background -> Cyan]A raster of an array of triples uses RGB colors by default:
a = {{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, {{.5, 0, 0}, {0, .5, 0}, {0, 0, .5}}};Graphics[Raster[a]]Graphics[Raster[a, ColorFunction -> RGBColor]]An array of four numbers is treated as having RGB values with opacity:
a = {{{1, 0, 0, 1}, {0, 1, 0, 1}, {0, 0, 1, 1}}, {{1, 0, 0, .5}, {0, 1, 0, .5}, {0, 0, 1, .5}}};Graphics[Raster[a], Background -> Cyan]Use Hue values for a scalar matrix:
a = {{0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1}};Graphics[Raster[a, ColorFunction -> Hue]]a = {{0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1}};Graphics[Raster[a, ColorFunction -> (Blend[{Red, Blue}, #]&)]]Use a color function with the specified range:
a = {{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};Graphics[Raster[a, Automatic, {0, 10}, ColorFunction -> (Blend[{Red, Blue}, #]&)]]a = {{0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1}};Graphics[Raster[a, ColorFunction -> "AvocadoColors"]]Generalizations & Extensions (1)
Any Wolfram Language expression can be applied to a color function:
a = {{x, y, y, z, z, z, x}};Graphics[Raster[a, ColorFunction -> (Switch[#, x, Red, y, Green, z, Blue]&)]]b = {{"Tomato", "Gold", "LawnGreen", "SteelBlue"}};Graphics[Raster[b, ColorFunction -> (ColorData["HTML", #]&)]]Options (4)
ColorFunction (4)
Graphics[Raster[{{0, 0.2, 0.4}, {0.6, 0.8, 1}}, ColorFunction -> GrayLevel]]Color the raster cells using hue values:
Graphics[Raster[{{0, 0.2, 0.4}, {0.6, 0.8, 1}}, ColorFunction -> Hue]]Use a user-defined color function:
Graphics[Raster[{{0, 0.2, 0.4}, {0.6, 0.8, 1}}, ColorFunction -> (RGBColor[#, #, 1 - #]&)]]Graphics[Raster[{Range[0, 1, .1]}, ColorFunction -> "TemperatureMap"]]Applications (3)
r = Raster[Table[i, {i, 100}, {j, 100}], {Scaled[{0, 0}], Scaled[{1, 1}]}, {1, 100}, ColorFunction -> "Pastel"];Plot[{Sin[x], Cos[x], Csc[x]}, {x, 0, 10}, Prolog -> r, PlotStyle -> Thick]Get a test RGB raster using ExampleData:
rgb = Reverse[ExampleData[{"TestImage", "Sailboat"}, "Data"] / 255.];Graphics[Raster[rgb]]gray = Map[{.3, .59, .11}.#&, rgb, {2}];Graphics[Raster[gray]]Apply a filter using ListCorrelate, then display it:
ker = {{1, 0, -1}, {1, 0, -1}, {1, 0, -1}};f = ListCorrelate[ker, gray];Graphics[Raster[f, Automatic, MinMax[f] / 4, ColorFunction -> "TemperatureMap"]]Define a simple raster density plot function:
rasterDensityPlot[f_, {xs_, xmin_, xmax_}, {ys_, ymin_, ymax_}, opts : OptionsPattern[rasterDensityPlot]] := Module[{raw, ppts, cf, zmin, zmax}, {ppts, cf} = OptionValue[{PlotPoints, ColorFunction}];raw = Table[f /. {xs -> j, ys -> i}, {i, ymin, ymax, (ymax - ymin) / (ppts - 1)}, {j, xmin, xmax, (xmax - xmin) / (ppts - 1)}];zmin = Min[raw];zmax = Max[raw];Graphics[Raster[raw, {{xmin, ymin}, {xmax, ymax}}, {zmin, zmax}, ColorFunction -> cf], FilterRules[{opts}, Options[Graphics]], AspectRatio -> 1, Frame -> True]]Options[rasterDensityPlot] = Sort@Join[{PlotPoints -> 50, ColorFunction -> "LakeColors"}, Options[Graphics]];rasterDensityPlot[x Sin[y], {x, -5, 5}, {y, 0, 10}, ColorFunction -> "AvocadoColors"]rasterDensityPlot[Sin[x] Sin[ y], {x, -4, 4}, {y, -4, 4}, ColorFunction -> "SunsetColors"]Properties & Relations (7)
Rotate can be applied to a raster:
Graphics[Rotate[Raster[Table[{i, j, .5}, {i, 0, 1, .1}, {j, 0, 1, .1}]], Pi / 6]]Use ArrayPlot when visualizing discrete data:
data = CellularAutomaton[30, {{1}, 0}, 20];{ArrayPlot[data], Graphics[Raster[data]]}Use ListDensityPlot when visualizing continuous data:
data = Table[Exp[-(x ^ 2 + y ^ 2)], {x, -1.5, 1.5, .1}, {y, -1.5, 1.5, 0.1}];{ListDensityPlot[data, FrameTicks -> None], Graphics[Raster[data]]}Use ReliefPlot to visualize elevation data:
data = Table[Evaluate[Sum[Sin[RandomReal[5, 2].{x, y}], {10}]], {x, 0, 10, .04}, {y, 0, 10, .04}];{ReliefPlot[data], Graphics[Raster[data, Automatic, {Min[data], Max[data]}]]}Rasterize can generate a raster graphic from any expression:
Rasterize[x ^ 2 + y ^ 2 == 1, "Graphics"]Head[First[%]]Rasterize[Graphics[{EdgeForm[Black], Pink, Disk[]}, ImageSize -> 100], "Graphics"]Head[First[%]]Rasterize[Graphics3D[Sphere[], ImageSize -> 100], "Graphics"]Head[First[%]]ExampleData contains a number of test images:
Short[ExampleData["TestImage"]]ExampleData[{"TestImage", "Man"}, "Graphics"]Head[First[%]]Many Import formats can produce Raster:
Import["ExampleData/coneflower.jpg", "Graphics"]Head[First[%]]Possible Issues (1)
Related Guides
Related Links
History
Introduced in 1991 (2.0) | Updated in 1996 (3.0) ▪ 1999 (4.0) ▪ 2000 (4.1) ▪ 2002 (4.2) ▪ 2003 (5.0) ▪ 2010 (8.0)
Text
Wolfram Research (1991), Raster, Wolfram Language function, https://reference.wolfram.com/language/ref/Raster.html (updated 2010).
CMS
Wolfram Language. 1991. "Raster." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2010. https://reference.wolfram.com/language/ref/Raster.html.
APA
Wolfram Language. (1991). Raster. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Raster.html
BibTeX
@misc{reference.wolfram_2026_raster, author="Wolfram Research", title="{Raster}", year="2010", howpublished="\url{https://reference.wolfram.com/language/ref/Raster.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_raster, organization={Wolfram Research}, title={Raster}, year={2010}, url={https://reference.wolfram.com/language/ref/Raster.html}, note=[Accessed: 13-June-2026]}