# Drawing filled circles (discs)

How about this solution? I'm a complete newbe, but this seems to do the trick. I didn't see a CircleCollection so I used CirclePolygon to generate vertices for a circle; these I grab and toss into a PolyCollection. Enjoy, Dave

import matplotlib
from matplotlib.patches import CirclePolygon from matplotlib.collections import PolyCollection import pylab

fig=pylab.figure()

N = 20
x = pylab.rand(N)
y = pylab.rand(N)
colors = 100*pylab.rand(N)
verts = []
for x1,y1,r in zip(x, y, radii):
circle = CirclePolygon((x1,y1), r)
verts.append(circle.get_verts())

p = PolyCollection(verts, cmap=matplotlib.cm.jet)
p.set_array(pylab.array(colors))
pylab.colorbar(p)

ax.axis('equal')
pylab.show()

···

-----Original Message-----
From: matplotlib-users-bounces@lists.sourceforge.net [mailto:matplotlib-users-bounces@lists.sourceforge.net] On Behalf Of Jouni K. Seppänen
Sent: Wednesday, September 19, 2007 11:03 AM
To: matplotlib-users@lists.sourceforge.net
Subject: Re: [Matplotlib-users] Drawing filled circles (discs)

sidimok <sidimok@...287...> writes:

Well, let's take the one you've proposed the last time. How than can i
put a colorbar beside the plot?

from matplotlib.colorbar import ColorbarBase, make_axes

and change the myscatter function to

def myscatter(ax, colormap, x, y, radii, colors):
for x1,y1,r,c in zip(x, y, radii, colormap(colors)):
cax, _ = make_axes(ax)
ColorbarBase(cax, cmap=colormap)

A better solution is probably to implement a CircleCollection similarly to the other collections.

--
Jouni K. Seppänen
http://www.iki.fi/jks

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Mika, David P (GE, Research) wrote:

trick. I didn't see a CircleCollection so I used CirclePolygon to
generate vertices for a circle; these I grab and toss into a
PolyCollection. Enjoy, Dave

Hi all!

Thank you very much indeed for the help, both solutions work like a charm.
However Dave's one gives rough cirlces, approximated by polygones, which is
not very accurate for my buisness. May I ask how to create a
circleCollection as Jouni "The Expert" proposed?
You can find below one of my plottings rendered by Jouni's first trick.

http://www.nabble.com/file/p12793350/image.png

···

--
View this message in context: http://www.nabble.com/Drawing-filled-circles-(discs)-tf4441651.html#a12793350
Sent from the matplotlib - users mailing list archive at Nabble.com.

In the solution I gave, CirclePolygon has a resolution argument for
number of vertices to approximate the circle (default=20). You could
increase that value to some more appropriate level:

import matplotlib
from matplotlib.patches import CirclePolygon
from matplotlib.collections import PolyCollection
import pylab

fig=pylab.figure()

resolution = 50 # the number of vertices
N = 20
x = pylab.rand(N)
y = pylab.rand(N)
colors = 100*pylab.rand(N)
verts = []
for x1,y1,r in zip(x, y, radii):
circle = CirclePolygon((x1,y1), r, resolution)
verts.append(circle.get_verts())

p = PolyCollection(verts, cmap=matplotlib.cm.jet)
p.set_array(pylab.array(colors))
pylab.colorbar(p)

ax.axis('equal')
pylab.show()

···

-----Original Message-----
From: matplotlib-users-bounces@lists.sourceforge.net
[mailto:matplotlib-users-bounces@lists.sourceforge.net] On Behalf Of
sidimok
Sent: Thursday, September 20, 2007 4:59 AM
To: matplotlib-users@lists.sourceforge.net
Subject: Re: [Matplotlib-users] Drawing filled circles (discs)

Mika, David P (GE, Research) wrote:

the trick. I didn't see a CircleCollection so I used CirclePolygon to

generate vertices for a circle; these I grab and toss into a
PolyCollection. Enjoy, Dave

Hi all!

Thank you very much indeed for the help, both solutions work like a
charm.
However Dave's one gives rough cirlces, approximated by polygones, which
is not very accurate for my buisness. May I ask how to create a
circleCollection as Jouni "The Expert" proposed?
You can find below one of my plottings rendered by Jouni's first trick.

http://www.nabble.com/file/p12793350/image.png
--
View this message in context:
http://www.nabble.com/Drawing-filled-circles-(discs)-tf4441651.html#
a12793350
Sent from the matplotlib - users mailing list archive at Nabble.com.

------------------------------------------------------------------------
-
This SF.net email is sponsored by: Microsoft Defy all challenges.
Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

import matplotlib
from matplotlib.patches import CirclePolygon
from matplotlib.collections import PolyCollection
import pylab

fig=pylab.figure()

resolution = 50 # the number of vertices
N = 20
x = pylab.rand(N)
y = pylab.rand(N)
colors = 100*pylab.rand(N)
verts = []
for x1,y1,r in zip(x, y, radii):
circle = CirclePolygon((x1,y1), r, resolution)
verts.append(circle.get_verts())

p = PolyCollection(verts, cmap=matplotlib.cm.jet)
p.set_array(pylab.array(colors))
pylab.colorbar(p)

ax.axis('equal')
pylab.show()

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Hi everyone,

The code above was working for me as a charm, but since the new matlplotlib
flavor 0.98, I'm getting this error message:

AttributeError: 'CirclePolygon' object has no attribute 'get_verts' <<

Any idea?

···

--
View this message in context: http://www.nabble.com/Drawing-filled-circles-(discs)-tp12672676p17849649.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

The new patches are more general since they work with general paths
and not just patches, but the snippet below is analogous::

verts = []
for x1,y1,r in zip(x, y, radii):
circle = CirclePolygon((x1,y1), r, resolution)
trans = circle.get_patch_transform()
path = circle.get_path()
transpath = path.transformed(trans)
verts.append(transpath.vertices

Note when you add the PolyCollection to the Axes, you should be use

p = PolyCollection(verts, cmap=matplotlib.cm.jet)
p.set_array(pylab.array(colors))

But I'm guessing you could use a RegularPolyCollection here anyhow...

Michael, do you think it is a good idea to add a get_verts
compatability method to the patches where it makes sense?

JDH

···

On Sun, Jun 15, 2008 at 7:48 AM, sidimok <sidimok@...287...> wrote:

The code above was working for me as a charm, but since the new matlplotlib
flavor 0.98, I'm getting this error message:

AttributeError: 'CirclePolygon' object has no attribute 'get_verts' <<

Any idea?

John Hunter wrote:

The code above was working for me as a charm, but since the new matlplotlib
flavor 0.98, I'm getting this error message:

AttributeError: 'CirclePolygon' object has no attribute 'get_verts' <<

Any idea?

The new patches are more general since they work with general paths
and not just patches, but the snippet below is analogous::

verts = []
for x1,y1,r in zip(x, y, radii):
circle = CirclePolygon((x1,y1), r, resolution)
trans = circle.get_patch_transform()
path = circle.get_path()
transpath = path.transformed(trans)
verts.append(transpath.vertices

Note when you add the PolyCollection to the Axes, you should be use

p = PolyCollection(verts, cmap=matplotlib.cm.jet)
p.set_array(pylab.array(colors))

But I'm guessing you could use a RegularPolyCollection here anyhow...

Or are you effectively doing a scatter plot? Could you use scatter?

Eric

···

On Sun, Jun 15, 2008 at 7:48 AM, sidimok <sidimok@...287...> wrote:

Michael, do you think it is a good idea to add a get_verts
compatability method to the patches where it makes sense?

JDH

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Or are you effectively doing a scatter plot? Could you use scatter?

Eric

Yes, I've already tried doing the trick with a scatter plot, but since the
filling colors correspond to a "physical quantity" and the radius of the
scatters are the "real" circle radius, using RegularPolygons is more
straightforward.

Isn't it better to use "Circle" new collection?

···

--
View this message in context: http://www.nabble.com/Drawing-filled-circles-(discs)-tp12672676p17879009.html
Sent from the matplotlib - users mailing list archive at Nabble.com.