7
$\begingroup$

In Mathematica, customizing Sections, Subsections, Titles and so on, can be done with Format > Style > .... Changing the background color of a style is one of the things you can do. Here is an example where I have colored the background orange:

enter image description here

But I want to change the background to show a color gradient. I mean, instead of having the same orange in all of the background, there should be a gradient so the orange fades from top to bottom. Gradient styles will be found in Palettes > Color Schemes. But I can't get it to work for changing the color of a cell background.

$\endgroup$
3
  • 1
    $\begingroup$ I don't know if it's possible to specify a gradient background (it may be in recent versions, but I don't think it is in v7 -- which I use). Nevertheless you can specify a bitmap fill for full control: (6318) $\endgroup$ Commented Jun 4, 2014 at 10:45
  • 2
    $\begingroup$ @Mr.Wizard youtube.com/watch?v=TQs3gVobcfg&feature=youtu.be&t=25s $\endgroup$ Commented Jun 4, 2014 at 12:52
  • $\begingroup$ @belisarius Crikey! =:-O $\endgroup$ Commented Jun 4, 2014 at 12:56

3 Answers 3

6
$\begingroup$

I'm not sure how exactly to integrate this with a stylesheet background, but here is a way to achieve gradients using Graphics:

Overlay@{ Graphics[ Raster@{List@@@Table[Blend["AvocadoColors",i],{i,0,1,.005}]}, AspectRatio->1/2, ImageSize->Full], Graphics[ Text@Style["Gradient!",FontSize->[email protected]], AspectRatio->1/2, ImageSize->Full]} 

enter image description here

EDIT

I stumbled on a different way to do this that would be easier for simple layouts (tidied up with kguler's suggestion):

Graphics[{ Polygon[ {{0, 0}, {1, 0}, {1, 1}, {0, 1}}, VertexColors -> {Yellow, Yellow, Green, Green}], Text[ Style["Gradient!", FontSize -> [email protected]], Scaled[{.5, .5}]]}, ImageSize -> Full, AspectRatio -> 1/2] 

enter image description here

$\endgroup$
2
  • $\begingroup$ You can do without Overlay putting Text[..] and Polygon[...] in a single Graphics: Graphics[{Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}, VertexColors -> {Yellow, Yellow, Green, Green}], Text[Style["Gradient!", FontSize -> [email protected]], Scaled[{.5, .5}]]}, ImageSize -> Full, AspectRatio -> 1/2] $\endgroup$ Commented Jun 6, 2014 at 19:28
  • $\begingroup$ @kguler I was just exercising my fingers :P $\endgroup$ Commented Jun 6, 2014 at 20:07
4
$\begingroup$

In versions 11.1+, you can use LinearGradientImage and add the text as Epilog:

Show[LinearGradientImage["BlueGreenYellow", 6 {100, 50}], Epilog -> {Text[Style["Gradient!", FontFamily -> "Old English Text MT", FontSize -> [email protected]], Scaled[{.5, .5}]]}] 

enter image description here

Replace "BlueGreenYellow" with {Black, Red, Orange, White} to get

enter image description here

Update: In versions 12.2.0+, gradient filling is available as a graphics directive:

Graphics[{LinearGradientFilling["BlueGreenYellow"], Rectangle[], Text[Style["Gradient!", FontSize -> [email protected]], Scaled[{.5, .5}]]}, AspectRatio -> 1/2] 

enter image description here

$\endgroup$
4
  • $\begingroup$ O my God!!! Surprising and amazing!!! Can we make use of such command in plotting. For example, Plot3D[Cos[x]Sin[y], {x...},{y,...}] I mean to have a plot gradient with arbitrary colors $\endgroup$ Commented Mar 17, 2020 at 8:32
  • $\begingroup$ @Unbelievable, you mean something like Plot3D[Cos[x] Sin[y], {x, 0, 2 Pi}, {y, 0, 2 Pi}, PlotStyle -> Texture[LinearGradientImage[{Black, Red, Orange, White}]], TextureCoordinateFunction -> ({#3, #2} &), Mesh -> None]? $\endgroup$ Commented Mar 17, 2020 at 8:47
  • $\begingroup$ ... or you can use a custom color function using Blend. For example, Plot3D[Cos[x] Sin[y], {x, 0, 2 Pi}, {y, 0, 2 Pi}, ColorFunction -> (Blend[{Black, Red, Orange, White}, #3] &), Mesh -> None] $\endgroup$ Commented Mar 17, 2020 at 8:49
  • $\begingroup$ You are right. I saw this function but I did not know that a set of colors can be chosen. Very amazing $\endgroup$ Commented Mar 17, 2020 at 9:12
2
$\begingroup$

The easy way to do this is to use Panel:

Panel[ Style["asdasd", FontSize -> 100, White], Appearance -> Rasterize@LinearGradientImage["BlueGreenYellow", 6 {100, 50}], ImageSize -> {500, 100} ] 

enter image description here

This Panel content can be messed with however you like. You can also make it so inside a certain Cell every Panel has the same Appearance by setting it at the style environment level. This works best if you use the BaseStyle option to Panel, since that lets you create targeted environments, but I'm just gonna show it like this:

Style[ Panel[ Style["asdasd", FontSize -> 100, White], ImageSize -> {500, 100} ], PanelBoxOptions -> { Appearance -> Rasterize@LinearGradientImage["BlueGreenYellow", 6 {100, 50}] } ] 

same image

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.