GrayLevel
Details
- GrayLevel is a color representing intensity in the monochrome grayscale color space as a shade of gray, where
represents black and
represents white. - The gray level must be a number between 0 and 1. »
- On display devices with no native gray‐level capability, dither patterns are typically used.
- If no opacity has been specified, GrayLevel[g] is equivalent to GrayLevel[g,1].
- GrayLevel[g,a] is equivalent to {GrayLevel[g],Opacity[a]}. »
- The alternative forms GrayLevel[{g}] and GrayLevel[{g,a}] can also be used.
- ColorConvert can be used to convert between GrayLevel and other color spaces.
- Style[expr,GrayLevel[…]] specifies that expr should be displayed with the specified gray level. »
- For 3D surfaces, explicit GrayLevel directives define surface colors; the final shading depends on lighting.
Examples
open all close allBasic Examples (4)
Specify the gray level of graphics primitives:
Graphics[{GrayLevel[.3], Disk[]}]Specify the gray level with opacity:
Graphics3D[{GrayLevel[.3, .5], Sphere[]}, Lighting -> "Neutral"]Specify the output gray level of expressions:
Style[x ^ 2 + y ^ 2, GrayLevel[.5]]Specify the gray level of plots:
Plot[Sin[x], {x, 0, 2Pi}, PlotStyle -> GrayLevel[.5]]Scope (1)
GrayLevel in 3D (1)
Graphics3D[{GrayLevel[.5], Sphere[]}, Lighting -> "Neutral"]Use diffuse and specular surface color:
Graphics3D[{GrayLevel[.5], Specularity[White, 20], Sphere[]}, Lighting -> "Neutral"]Use glow color, setting the diffuse surface color to black:
Graphics3D[{Black, Glow[GrayLevel[.5]], Sphere[]}]Generalizations & Extensions (1)
Table[Graphics[{GrayLevel[0], Disk[{1, 0}], Opacity[a], GrayLevel[1 / 2], Disk[]}], {a, 0, 1, .33}]Use the opacity argument directly in GrayLevel:
Table[Graphics[{GrayLevel[0], Disk[{1, 0}], GrayLevel[1 / 2, a], Disk[]}], {a, 0, 1, .33}]Properties & Relations (1)
GrayLevel of RGBColor can be computed in the following way:
RGBToGray[RGBColor[r_, g_, b_]] := GrayLevel[.299r + .587g + .144b];c = RGBColor@@RandomReal[{0, 1}, 3];
{Graphics[{c, Rectangle[]}], Graphics[{RGBToGray[c], Rectangle[]}]}From this formula we see that many colors will produce the same gray level G:
Solve[.299 r + .587 g + .144 b == G, r]Use a color function in the RGB color space:
DensityPlot[g, {g, 0, 1}, {b, 0, 1}, ColorFunction -> Function[{b, g}, RGBColor[3.34448 (0.5 - 0.144 b - 0.587 g), g, b]]]The corresponding gray-level colors:
DensityPlot[g, {g, 0, 1}, {b, 0, 1}, ColorFunction -> Function[{b, g}, RGBToGray[RGBColor[3.34448 (0.5 - 0.144 b - 0.587 g), g, b]]]]Possible Issues (2)
Gray-level values outside of the 0,1 range will be clipped:
Graphics[Table[{GrayLevel[g], EdgeForm[Gray], Rectangle[{4g, 0}]}, {g, 0 - 1 / 4, 1 + 1 / 4, 1 / 4}]]The actual surface color depends on the colors of lights in 3D:
Graphics3D[{GrayLevel[.5], Specularity[White, 20], Sphere[]}, Lighting -> {{"Point", Red, Scaled[{2, 0, 0}]}, {"Point", Green, Scaled[{0, -2, 0}]}, {"Point", Blue, Scaled[{0, 0, 2}]}}]The default 3D lights contain several colored light sources:
Graphics3D[{GrayLevel[.5], Specularity[White, 20], Sphere[]}]Neat Examples (2)
Visualizing the gray level with opacity:
Graphics3D[ {Table[ {GrayLevel[i, j], Cuboid[{i, j, 0}, {i, j, 0} + 0.1]}, {i, 0, 1, 0.2}, {j, 0, 1, 0.2}]}, Axes -> True, AxesLabel -> {"GrayLevel", "Opacity"}, Lighting -> "Neutral"]Graphics[{Pink, Disk[{100, 100}, 40], Raster[RandomReal[1, {200, 200, 2}], ColorFunction -> GrayLevel]}]See Also
RGBColor Hue Lighter Darker Black White Gray Raster Opacity Blend Lighting ColorSlider ColorConvert ConstantImage
Function Repository: FaustGrayscaleConvert
Related Guides
History
Introduced in 1988 (1.0) | Updated in 2007 (6.0) ▪ 2008 (7.0) ▪ 2021 (12.3)
Text
Wolfram Research (1988), GrayLevel, Wolfram Language function, https://reference.wolfram.com/language/ref/GrayLevel.html (updated 2021).
CMS
Wolfram Language. 1988. "GrayLevel." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2021. https://reference.wolfram.com/language/ref/GrayLevel.html.
APA
Wolfram Language. (1988). GrayLevel. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/GrayLevel.html
BibTeX
@misc{reference.wolfram_2026_graylevel, author="Wolfram Research", title="{GrayLevel}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/GrayLevel.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_graylevel, organization={Wolfram Research}, title={GrayLevel}, year={2021}, url={https://reference.wolfram.com/language/ref/GrayLevel.html}, note=[Accessed: 12-June-2026]}