Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Gradient fill as Background for Plot

251 views
Skip to first unread message

leh...@gmail.com

unread,
Jun 14, 2008, 5:30:33 AM6/14/08
to
Hello,
I wish Plot to have gradient fill background (from right bottom to
left top the fill color becomes lighter). I hope there is simple
solution but I did not find in the Documentation any example for
this.
I have found a simple nice solution for uniform fill:
Plot[-1/x, {x, -1, 0}, Background -> Lighter[Yellow, .8]]
But I have not find how to make gradient fill.
Does anyone know a solution?

P.S. More commonly, I would like to know (if it is possible) how I can
specify any arbitrary (may be piecewise) function for filling the
Background.

David Park

unread,
Jun 15, 2008, 6:17:47 AM6/15/08
to
You can use a DensityPlot as a background. But you may want to specify the
specific PlotRange so it will coordinate with the other plot elements. Here
is how I would do it with the Presentations package. We just draw the
background first and then put the other plot elements on top of it. Rescale
is a convenient method to control what values are fed to the color function.


Needs["Presentations`Master`"]

Draw2D[
{DensityDraw[
Rescale[-Rescale[x, {-1, 0}] + Rescale[y, {0, 12}], {-1,
1}], {x, -1, 0}, {y, 0, 12},
ColorFunctionScaling -> False,
ColorFunction -> (Blend[{Yellow, White}, #] &)
],
Draw[-1/x, {x, -1, 0}]},
AspectRatio -> 1/2,
Frame -> True]

For something more colorful you could try:

Draw2D[
{DensityDraw[
Rescale[-Rescale[x, {-1, 0}] + Rescale[y, {0, 12}], {-1,
1}], {x, -1, 0}, {y, 0, 12},
ColorFunctionScaling -> False,
ColorFunction -> ColorData["BeachColors"]
],
Draw[-1/x, {x, -1, 0}]},
AspectRatio -> 1/2,
Frame -> True]

Since you can make the DensityPlot anything you want you can have any kind
of background.

--
David Park
djm...@comcast.net
http://home.comcast.net/~djmpark/


<leh...@gmail.com> wrote in message news:g3033p$maq$1...@smc.vnet.net...

leh...@gmail.com

unread,
Jun 16, 2008, 6:43:33 AM6/16/08
to
On 15 =C9=C0=CE, 14:17, "David Park" <djmp...@comcast.net> wrote:
> You can use a DensityPlot as a background. But you may want to specify the
> specific PlotRange so it will coordinate with the other plot elements. Here
> is how I would do it with the Presentations package. We just draw the
> background first and then put the other plot elements on top of it. Rescale
> is a convenient method to control what values are fed to the color function.

Thank you for the idea! Just now I have found very nice particular
ready-for-use solution in the Documentation Center! It is located on
"Prolog" page under "Applications" field. It is:

bg = Polygon[{ImageScaled[{0, 0}], ImageScaled[{1, 0}],
ImageScaled[{1, 1}], ImageScaled[{0, 1}]},
VertexColors -> {LightYellow, LightYellow, LightYellow, White}];
Plot[-1/x, {x, -1, 0}, Prolog -> bg, PlotRangeClipping -> False]

As I understand there should be some way for using DensityPlot as
Prolog but DensityPlot is not a list of graphics primitives and so may
not be directly passed to Prolog. Does anyone know how to convert
DensityPlot for using as Prolog?


David Park

unread,
Jun 18, 2008, 4:24:35 AM6/18/08
to
Thanks for pointing out the use of VertexColors.

On your last question you could take the First part of DensityPlot to obtain
the primitives.

Plot[-1/x, {x, -1, 0},

Prolog -> {First@DensityPlot[12 x - y, {x, -1, 0}, {y, 0, 12.2}]},
PlotRangeClipping -> False]

The regular Mathematica graphics paradigm presents a barrier to many users
because to make custom plots and geometric diagrams it is necessary to jump
between graphical levels using various combinations of Show, Graphics,
Prolog, Epilog and First. It's not that it's terribly difficult to do this
but it's enough to stop many users. The Presentations package converts
everything to graphical primitives so there is a uniform simple syntax for
doing graphics. You can combine primitives and curves or surfaces together
in one container. You just draw one thing after another. You don't have to
use Show, Graphics, Prolog, Epilog or First. So, for your two plots we could
use the following.

Needs["Presentations`Master`"]

Combining graphical primitives with a Plot curve:

Draw2D[
{Polygon[{ImageScaled[{0, 0}], ImageScaled[{1, 0}],


ImageScaled[{1, 1}], ImageScaled[{0, 1}]},

VertexColors -> {LightYellow, Yellow, LightYellow, White}],
Draw[-1/x, {x, -1, 0}]},
AspectRatio -> .6,
Axes -> True]

Combining a DensityPlot with a Plot curve:

Draw2D[
{DensityDraw[12 x - y, {x, -1, 0}, {y, 0, 12.2}],
Draw[-1/x, {x, -1, 0}]},
AspectRatio -> .6,
Axes -> True]


<leh...@gmail.com> wrote in message news:g35g4l$9fb$1...@smc.vnet.net...

leh...@gmail.com

unread,
Jun 19, 2008, 5:42:49 AM6/19/08
to
On 18 June, 12:24, "David Park" <djmp...@comcast.net> wrote:
> Thanks for pointing out the use of VertexColors.
>
> On your last question you could take the First part of DensityPlot to obt=
ain
> the primitives.

>
> Plot[-1/x, {x, -1, 0},
> Prolog -> {First@DensityPlot[12 x - y, {x, -1, 0}, {y, 0, 12.2}]},
> PlotRangeClipping -> False]

Thank you very much! It is simple and straightforward! But there
appears additional question: how to make this DensityPlot-background
to fill all image? The option "PlotRangeClipping -> False" gives only
little help. The axes in the Plot gets out of the DensityPlot-
background. I have tried "ImageSize" option for DensityPlot but it
does nothing in this case.

> The regular Mathematica graphics paradigm presents a barrier to many user=
s
> because to make custom plots and geometric diagrams it is necessary to ju=
mp


> between graphical levels using various combinations of Show, Graphics,

> Prolog, Epilog and First. It's not that it's terribly difficult to do thi=
s


> but it's enough to stop many users. The Presentations package converts

> everything to graphical primitives so there is a uniform simple syntax fo=
r
> doing graphics. You can combine primitives and curves or surfaces togethe=
r
> in one container. You just draw one thing after another. You don't have t=
o
> use Show, Graphics, Prolog, Epilog or First. So, for your two plots we co=
uld


> use the following.
>
> Needs["Presentations`Master`"]
>
> Combining graphical primitives with a Plot curve:
>
> Draw2D[
> {Polygon[{ImageScaled[{0, 0}], ImageScaled[{1, 0}],
> ImageScaled[{1, 1}], ImageScaled[{0, 1}]},

> VertexColors -> {LightYellow, Yellow, LightYellow, White}],


> Draw[-1/x, {x, -1, 0}]},

> AspectRatio -> .6,
> Axes -> True]
>
> Combining a DensityPlot with a Plot curve:
>
> Draw2D[

> {DensityDraw[12 x - y, {x, -1, 0}, {y, 0, 12.2}],


> Draw[-1/x, {x, -1, 0}]},

> AspectRatio -> .6,
> Axes -> True]
>
> --
> David Park

> djmp...@comcast.nethttp://home.comcast.net/~djmpark/

It is interesting but Draw2D also produces graphical primitives? Or it
simply converts any passed Graphics-object to graphical primitives?


0 new messages