BackgroundColor, BackgroundColor2

Background color

Value Summary

BackgroundColor, BackgroundColor2InheritedColor

Graphics Primitives

ObjectsDefault Values
plot::Canvas, plot::Scene2d

BackgroundColor: RGB::White

plot::Scene3d

BackgroundColor: RGB::White

BackgroundColor2: RGB::Grey75

Description

These attributes set background colors for scenes, scene margins, and the remaining space in a canvas.

BackgroundColor sets the background color of a scene or canvas, where "background" refers to any area not occupied by graphical elements, including the margin.

For a 3D-scene, if BackgroundStyle is not Flat, the actual scene background (not including the margin) is a blend from BackgroundColor to BackgroundColor2. See BackgroundStyle for details.

Examples

Example 1

In the following plot, we combine three scenes with backgrounds in red, blue, and green and set the background color of the canvas to yellow:

s1 := plot::Scene3d(plot::Sphere(1, Color = RGB::White),
                    BackgroundColor = RGB::Red):
s2 := plot::modify(s1, BackgroundColor = RGB::Blue):
s3 := plot::modify(s1, BackgroundColor = RGB::Green):
plot(s1, s2, s3, BackgroundColor = RGB::Yellow):

Example 2

Using BackgroundColor2 and BackgroundStyle, you can set the background of 3D-scenes to use a color blend:

plotfunc3d(x^2-y^2, 
           BackgroundStyle = LeftRight,
           BackgroundColor2 = RGB::Chartreuse)

But note that the margin of the scene is still painted in its BackgroundColor:

plotfunc3d(x^2-y^2,
           plot::Scene3d::BackgroundColor = RGB::Yellow,
           plot::Scene3d::BackgroundStyle = LeftRight,
           plot::Scene3d::BackgroundColor2 = RGB::LightBlue)

To avoid this margin, we set its width to zero:

plotfunc3d(x^2-y^2,
           plot::Scene3d::BackgroundColor = RGB::Yellow,
           plot::Scene3d::BackgroundStyle = LeftRight,
           plot::Scene3d::BackgroundColor2 = RGB::LightBlue,
           plot::Scene3d::Margin = 0)

Example 3

The fact that BackgroundColor is an attribute of both canvas and scenes has the effect that giving it directly in a plot command will only affect the canvas, not the implicitly generated scenes of a plot:

plot(plot::Circle2d(1),
     BackgroundColor = RGB::Yellow)

plotfunc2d(sin(x), BackgroundColor = RGB::Black)

To set the background color of a scene, use one of the styles illustrated above: Either create a scene explicitly:

plot(plot::Scene2d(plot::Circle2d(1),
                   BackgroundColor = RGB::Yellow))

Or, set the attribute explicitly for scenes:

plotfunc2d(sin(x),
           plot::Scene2d::BackgroundColor = RGB::Orange)

There is also a third option, not used in the examples above: You can set BackgroundColor as a hint in an object to be shown (but this does not work for plotfunc2d and plotfunc3d):

plot(plot::Text2d("Sample", [0, 0],
                  TextFont = [RGB::White, 60],
                  HorizontalAlignment = Center,
                  BackgroundColor = RGB::Black))

See Also

MuPAD Functions

Was this topic helpful?