Raster
更多信息和选项
- Raster[array,ColorFunctionf] 指定每个单元应当使用将函数 f 应用到该单元得到的图形指令来着色.
- 如果 array 的维数为 {n,m},则假定 Raster[array] 要填充矩形 Rectangle[{0,0},{m,n}]. »
- Raster[array,{{xmin,ymin},{xmax,ymax}}] 指定用栅格填充矩形Rectangle[{xmin,ymin},{xmax,ymax}]. »
- 可以使用 Scaled 和 Offset 来指定矩形的坐标.
- Raster[array,Automatic] 等价于 Raster[array,{{0,0},{m,n}}].
- Raster[array,rect,{amin,amax}] 指定缩放单元值,这样使得 amin 对应于0,amax 对应于1. 这个范围外的单元值剪切为 0 或 1.
- array 可以是一个 SparseArray 对象.
- Image[Raster[…]] 转换一个 Raster 对象为一个图像.
范例
打开所有单元 关闭所有单元基本范例 (4)
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}}}]]Graphics[{{Red, Disk[{5, 5}, 4]}, Raster[Table[{1 - x, y}, {x, .1, 1, .1}, {y, .1, 1, .1}]]}]Graphics[{{Red, Disk[{5, 5}, 4]}, Raster[Table[{x, y, x, y}, {x, .1, 1, .1}, {y, .1, 1, .1}]]}]范围 (14)
Raster 详细说明 (3)
对于一个
×
矩形,栅格占用从 {0,0} 到 {m,n} 的矩形:
a = {{0, 0.2, 0.4}, {0.6, 0.8, 1}};Graphics[Raster[a], Frame -> True, FrameTicks -> False]Graphics[Raster[a, {{0, 1}, {5, 4}}], PlotRange -> {{0, 5}, {0, 5}}, Frame -> True]用 Scaled 和 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]用 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 样式 (11)
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]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]a = {{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};Graphics[Raster[a, Automatic, {2, 8}], Frame -> True, FrameTicks -> False]a = {{{0, .2}, {0, .4}, {0, .5}, {0, .6}, {0, .8}, {0, 1}}};Graphics[Raster[a], Background -> Cyan]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]]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]对标量矩阵用 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 -> 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}, #]&)]]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"]]推广和延伸 (1)
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", #]&)]]选项 (4)
ColorFunction (4)
Graphics[Raster[{{0, 0.2, 0.4}, {0.6, 0.8, 1}}, ColorFunction -> GrayLevel]]Graphics[Raster[{{0, 0.2, 0.4}, {0.6, 0.8, 1}}, ColorFunction -> Hue]]Graphics[Raster[{{0, 0.2, 0.4}, {0.6, 0.8, 1}}, ColorFunction -> (RGBColor[#, #, 1 - #]&)]]Graphics[Raster[{Range[0, 1, .1]}, ColorFunction -> "TemperatureMap"]]应用 (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]用 ExampleData 获得一个实验 RGB 栅格:
rgb = Reverse[ExampleData[{"TestImage", "Sailboat"}, "Data"] / 255.];Graphics[Raster[rgb]]gray = Map[{.3, .59, .11}.#&, rgb, {2}];Graphics[Raster[gray]]用 ListCorrelate 做一个滤波,然后显示它:
ker = {{1, 0, -1}, {1, 0, -1}, {1, 0, -1}};f = ListCorrelate[ker, gray];Graphics[Raster[f, Automatic, MinMax[f] / 4, ColorFunction -> "TemperatureMap"]]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"]属性和关系 (7)
Rotate 可以应用到一个栅格上:
Graphics[Rotate[Raster[Table[{i, j, .5}, {i, 0, 1, .1}, {j, 0, 1, .1}]], Pi / 6]]可视化离散数据时用 ArrayPlot:
data = CellularAutomaton[30, {{1}, 0}, 20];{ArrayPlot[data], Graphics[Raster[data]]}可视化连续数据时用 ListDensityPlot:
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]]}可视化高度数据时用 ReliefPlot:
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 可以从任何表达式中产生一个栅格图形:
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 包含一定数量的实验图形:
Short[ExampleData["TestImage"]]ExampleData[{"TestImage", "Man"}, "Graphics"]Head[First[%]]Import["ExampleData/coneflower.jpg", "Graphics"]Head[First[%]]可能存在的问题 (1)
相关指南
历史
1991年引入 (2.0) | 在以下年份被更新:1996 (3.0) ▪ 1999 (4.0) ▪ 2000 (4.1) ▪ 2002 (4.2) ▪ 2003 (5.0) ▪ 2010 (8.0)
文本
Wolfram Research (1991),Raster,Wolfram 语言函数,https://reference.wolfram.com/language/ref/Raster.html (更新于 2010 年).
CMS
Wolfram 语言. 1991. "Raster." Wolfram 语言与系统参考资料中心. Wolfram Research. 最新版本 2010. https://reference.wolfram.com/language/ref/Raster.html.
APA
Wolfram 语言. (1991). Raster. Wolfram 语言与系统参考资料中心. 追溯自 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: 01-November-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: 01-November-2026]}