MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Primitive Disk Gradient Fills in Graphics

  • To: mathgroup at
  • Subject: [mg110979] Re: Primitive Disk Gradient Fills in Graphics
  • From: "David Park" <djmpark at>
  • Date: Thu, 15 Jul 2010 03:10:59 -0400 (EDT)

Well, darn if there isn't a method for doing that within BubbleChart.



for the various types of bubbles. Then, for example:

BubbleChart[RandomReal[1, {10, 3}],
 ChartStyle -> "Pastel",
 ChartElementFunction -> "GradientBubble"] 

But how would we obtain different colors for the bubbles, say based on the
radius? I don't know where we can feed it in.

Instead of starting with high level, "set-piece" plot types, and then trying
to screw them around with convoluted options, it would be much easier to
start with primitives and build up the higher level plot types.

Suppose I want a bubble fading from White to a color at the rim, and I want
different colors depending on the radius of the bubble? Here is an easy way
to build it up.


First define the primitive.

gradientDisk::usage = 
  "gradientDisk[{xcenter, ycenter}, radius, color] will draw an \
outlined disk with the color blended from White to full color across \
the radius.";
   gradientDisk] = {"ArgumentsPattern" -> {{_, _}, _, _}};
gradientDisk[{xcenter_, ycenter_}, radius_, color_] :=
 {RegionDraw[(x - xcenter)^2 + (y - ycenter)^2 < radius^2, {x, 
    xcenter - radius, xcenter + radius}, {y, ycenter - radius, 
    ycenter + radius},
   ColorFunctionScaling -> False,
   ColorFunction -> 
    Function[{x, y}, 
     Blend[{White, color}, 
      Rescale[Sqrt[(x - xcenter)^2 + (y - ycenter)^2], {0, radius}]]]],
  Circle[{xcenter, ycenter}, radius]} 

Adapt it to the WRI form of Bubble data with a particular color selection
for the bubbles.

myBubble[{x_, y_, r_}] := 
 gradientDisk[{x, y}, r, ColorData["SolarColors"][Rescale[r, {0, 2}]]]

Then draw the bubble chart.

data = Array[{RandomReal[{-10, 10}], RandomReal[{-10, 10}], 
     RandomReal[{0.1, 2}]} &, 20];
 {myBubble /@ data},
 Frame -> True,
 ImageMargins -> 5,
 PlotRange -> 12

Also, since WRI must have defined a primitive for SquareWaveBubble, say, how
could we obtain direct access to it? (I know how to program one but since
WRI has done, and buried, the work how about getting it out?)

David Park
djmpark at  

From: M.Roellig [mailto:markus.roellig at] 

On 13 Jul., 11:28, Murta <rodrigomur... at> wrote:
> Hello All
>    There is really no way to do a simple gradient fill inside a disk
> in Mathematica?
>    I'm working in a BubbleChart, and would like to make a graphics
> disk using ChartElements, going to color x to transparent using
> opacity.
>    I get surprised to see that there is no way to work with gradient
> fill inside primitives like Disk.. there is really this?
>    If it's true, please, correct it in Mathematica 8!...


I agree, GradientFill would be nice, as well as TextureFill or any filling
with arbitrary patterns. Until then you can try to construct it by yourself:

GradientDisk[] :=
 Graphics[Table[{Hue[r], Circle[{0, 0}, r]}, {r, 0, 1, 0.001}]] ;
BubbleChart[RandomReal[1, {10, 3}], ChartElements -> {GradientDisk[]}]


BWGradientDisk[] :=
 Graphics[Table[{GrayLevel[r], Circle[{0, 0}, r]}, {r, 0, 1,
BubbleChart[RandomReal[1, {10, 3}],
 ChartElements -> {BWGradientDisk[]}]

This takes quite some time, since many Circles are drawn. If somebody knows
how to rasterize a circly without getting square image borders, one
could use the rasterized image as Element. Maybe exporting to gif
with transparent white background works.

Of course, the same excercise also works with Rectangles etc..



  • Prev by Date: Re: Primitive Disk Gradient Fills in Graphics
  • Next by Date: Generate #s
  • Previous by thread: Re: Primitive Disk Gradient Fills in Graphics
  • Next by thread: Re: Primitive Disk Gradient Fills in Graphics