4
$\begingroup$

Is there a way to manually make a black transparent background like the one in the Marketing theme? As an example, let's say I have the following code:

Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}, PlotTheme -> "Marketing"]

which gives me the following result:

marketing

Suppose I wish to manually make the transparent black background of the Marketing theme or maybe change it to any other color, or shift the background from back to front or left to right.

How to manually accomplish this task without invoking PlotTheme -> Marketing?

$\endgroup$
3

4 Answers 4

5
$\begingroup$

I will show how to find out how "Marketing" works. You can adopt and adapt its features to suit yourself.

One can find how a plot theme works as follows:

Charting`ResolvePlotTheme["Marketing", Plot3D] // Map@InputForm // 
 Column[#, Dividers -> All] &
(* output is a somewhat lengthy list of options *)

The style of background in "Marketing" depends on three options, DisplayFunction, FaceGrids, and FaceGridsStyle. The display function manually constructs the rectangles using scaled coordinates so that they always align with faces of the bounding box. You can change the scaled coordinates to change their placement.

DisplayFunction /. Charting`ResolvePlotTheme["Marketing", Plot3D] // InputForm
(*
Charting`noShow[#1, Graphics3D[{{JoinForm["Round"], EdgeForm[{}], 
     Polygon[{Scaled[{0, 0, 0}], Scaled[{0, 1, 0}], Scaled[{1, 1, 0}], 
       Scaled[{1, 0, 0}]}, VertexColors -> {GrayLevel[0, 0.7], GrayLevel[0, 0.9], 
        GrayLevel[0, 0.7], GrayLevel[0, 0.5]}], 
     Polygon[{Scaled[{0, 0, 0}], Scaled[{0, 0, 1}], Scaled[{0, 1, 1}], 
       Scaled[{0, 1, 0}]}, VertexColors -> {GrayLevel[0, 0.9], GrayLevel[0, 0.5], 
        GrayLevel[0, 0.5], GrayLevel[0, 0.9]}], 
     Polygon[{Scaled[{0, 1, 0}], Scaled[{0, 1, 1}], Scaled[{1, 1, 1}], 
       Scaled[{1, 1, 0}]}, VertexColors -> {GrayLevel[0, 0.9], GrayLevel[0, 0.5], 
        GrayLevel[0, 0.5], GrayLevel[0, 0.9]}]}, 
    {Thick, Gray, Line[{Scaled[{0, 0, 0}], Scaled[{0, 1, 0}], 
       Scaled[{0, 1, 1}]}], Line[{Scaled[{0, 1, 0}], Scaled[{1, 1, 0}]}]}}]] &
*)

Extract the background rectangles:

myBackground = 
  Graphics3D[{{JoinForm["Round"], EdgeForm[{}], 
     Polygon[{Scaled[{0, 0, 0}], Scaled[{0, 1, 0}], Scaled[{1, 1, 0}], 
       Scaled[{1, 0, 0}]}, 
      VertexColors -> {GrayLevel[0, 0.7], GrayLevel[0, 0.9], 
        GrayLevel[0, 0.7], GrayLevel[0, 0.5]}], 
     Polygon[{Scaled[{0, 0, 0}], Scaled[{0, 0, 1}], Scaled[{0, 1, 1}], 
       Scaled[{0, 1, 0}]}, 
      VertexColors -> {GrayLevel[0, 0.9], GrayLevel[0, 0.5], 
        GrayLevel[0, 0.5], GrayLevel[0, 0.9]}], 
     Polygon[{Scaled[{0, 1, 0}], Scaled[{0, 1, 1}], Scaled[{1, 1, 1}], 
       Scaled[{1, 1, 0}]}, 
      VertexColors -> {GrayLevel[0, 0.9], GrayLevel[0, 0.5], 
        GrayLevel[0, 0.5], GrayLevel[0, 0.9]}]}, {Thick, Gray, 
     Line[{Scaled[{0, 0, 0}], Scaled[{0, 1, 0}], Scaled[{0, 1, 1}]}], 
     Line[{Scaled[{0, 1, 0}], Scaled[{1, 1, 0}]}]}}];

Instead of using the internal function, use Show for the display function. I copied the face grid and style from the output of ResolvePlotTheme.

Plot3D[Sin[x  y], {x, 0, 3}, {y, 0, 3},
 DisplayFunction -> (Show[#, myBackground] &),
 FaceGrids -> {{-1, 0, 0}, {0, 1, 0}, {0, 0, -1}},
 FaceGridsStyle -> Directive[AbsoluteThickness[1], GrayLevel[0, 0.2]]]

enter image description here

Giving colors to each vertex of the polygons in the background creates a gradient. It makes the back corners look like they're in a shadow. You can remove the vertex color options from the polygons and style them with a plain color if you wish. Or keep the options and change the colors and opacities.

$\endgroup$
6
$\begingroup$

This is just for changing the color.

color = ColorData[97, 3];

Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}, PlotTheme -> "Marketing"] /. 
 Thread[{GrayLevel[0, 0.5`], GrayLevel[0, 0.7`], 
    GrayLevel[0, 0.9`]} -> {Opacity[0.5, color], Opacity[0.7, color], 
    Opacity[0.9, color]}]

enter image description here

shift the background from back to front or left to right

This would need more work which I am lazy to do.

$\endgroup$
5
$\begingroup$

A shorter variant of azerbajdzan's answer

Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}, PlotTheme -> "Marketing"] /. 
 GrayLevel[_, _] :> Opacity[1, ColorData[97, 1]]

enter image description here

$\endgroup$
1
$\begingroup$

Try

pic=Plot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}, PlotTheme -> "Marketing"]
AbsoluteOptions[bild, BaseStyle]
(*{BaseStyle -> Specularity[GrayLevel[0.5], 30.]}*)
$\endgroup$
3
  • $\begingroup$ Have you tried? What did you get? $\endgroup$ Commented Feb 23 at 11:39
  • $\begingroup$ Specularity[GrayLevel[0.5], 30.] $\endgroup$ Commented Feb 23 at 11:52
  • 2
    $\begingroup$ I see but show us how to use it to change the background color. $\endgroup$ Commented Feb 23 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.