This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

BackgroundColor, BackgroundColor2

Background color

MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

Value Summary

BackgroundColor, BackgroundColor2InheritedColor

Graphics Primitives

ObjectsDefault Values
plot::Canvas, plot::Scene2d

BackgroundColor: RGB::White


BackgroundColor: RGB::White

BackgroundColor2: RGB::Grey75


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.


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:

           BackgroundStyle = LeftRight,
           BackgroundColor2 = RGB::Chartreuse)

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

           plot::Scene3d::BackgroundColor = RGB::Yellow,
           plot::Scene3d::BackgroundStyle = LeftRight,
           plot::Scene3d::BackgroundColor2 = RGB::LightBlue)

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

           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:

     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:

                   BackgroundColor = RGB::Yellow))

Or, set the attribute explicitly for scenes:

           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?