Skip to content

Commit 71a41ff

Browse files
committed
added polar demos
svn path=/trunk/matplotlib/; revision=615
1 parent 8193c81 commit 71a41ff

File tree

7 files changed

+43
-12
lines changed

7 files changed

+43
-12
lines changed

CHANGELOG

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ New entries should be added at the top
2020
2004-09-30 Added Andrew Dalke's strftime code to extend the range of
2121
dates supported by the DateFormatter - JDH
2222

23-
2004-09-30 Added hbar - JDH
23+
2004-09-30 Added barh - JDH
2424

2525
2004-09-30 Removed fallback to alternate array package from numerix
2626
so that ImportErrors are easier to debug. JTM

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ RELEASE = matplotlib-${VERSION}
1212

1313
clean:
1414
${PYTHON} setup.py clean;\
15+
rm -f *.png *.ps *.eps *.svg
1516
find . -name "_tmp*.py" | xargs rm -f;\
1617
find . \( -name "*~" -o -name "*.pyc" \) | xargs rm -f;\
1718
find examples \( -name "*.svg" -o -name "*.png" -o -name "*.ps" -o -name "*.jpg" -o -name "*.eps" -o -name "*.tar" -name "*.gz" \) | xargs rm -f

examples/polar_demo.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,18 @@
5353

5454
from matplotlib.matlab import *
5555

56-
r = arange(0,4,0.001)
57-
theta = 6*pi*r
58-
polar(theta, r)
59-
title("It's about time!")
60-
savefig('polar_demo')
61-
ax = gca()
56+
# radar green, solid grid lines
57+
rc('grid', color='#316931', linewidth=1, linestyle='-')
58+
rc('tick', labelsize=15)
59+
# force square figure and square axes looks better for polar, IMO
60+
figure(figsize=(8,8))
61+
ax = axes([0.1, 0.1, 0.8, 0.8], polar=True, axisbg='#d5de9c')
62+
63+
r = arange(0,1,0.001)
64+
theta = 2*2*pi*r
65+
polar(theta, r, color='#ee8d18', lw=3)
66+
set(ax.thetagridlabels, y=1.075) # the radius of the grid labels
6267

68+
title("And there was much rejoicing!", fontsize=20)
69+
savefig('polar_demo')
6370
show()

examples/polar_demo2.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env python
2+
# a polar scatter plot; size increases radially in this example and
3+
# color increases with angle (just to verify the symbols are being
4+
# scattered correctlu). In a real example, this would be wasting
5+
# dimensionlaity of the plot
6+
from matplotlib.matlab import *
7+
8+
N = 150
9+
r = 2*rand(N)
10+
theta = 2*pi*rand(N)
11+
area = 200*r**2*rand(N)
12+
colors = theta
13+
ax = subplot(111, polar=True)
14+
c = scatter(theta, r, c=colors, s=area)
15+
c.set_alpha(0.75)
16+
17+
#savefig('polar_scatter')
18+
show()

lib/matplotlib/axes.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -2800,7 +2800,7 @@ class PolarAxes(Axes):
28002800
thetagridlines : a list of Line2D for the theta grids
28012801
rgridlines : a list of Line2D for the radial grids
28022802
thetagridlabels : a list of Text for the theta grid labels
2803-
rgridlabels : a list of Text for the theta grid labels
2803+
rgridlabels : a list of Text for the theta grid labels
28042804
28052805
"""
28062806

@@ -2837,6 +2837,7 @@ def cla(self):
28372837

28382838
self._gridOn = rcParams['polaraxes.grid']
28392839
self.lines = []
2840+
self.collections = []
28402841
self.texts = [] # text in axis coords
28412842

28422843
self.grid(self._gridOn)
@@ -2973,6 +2974,8 @@ def draw(self, renderer):
29732974
for t in self.texts:
29742975
t.draw(renderer)
29752976

2977+
for c in self.collections:
2978+
c.draw(renderer)
29762979
self.title.draw(renderer)
29772980
self.transData.thaw() # release the lazy objects
29782981
self.transAxes.thaw() # release the lazy objects
@@ -3013,7 +3016,7 @@ def set_thetagridlabels(self, angles, fmt='%d', frac = 1.1, **kwargs):
30133016
self.thetagridlabels.append(t)
30143017
return self.thetagridlabels
30153018

3016-
def set_rgridlabels(self, radii, angle=67.5, **kwargs):
3019+
def set_rgridlabels(self, radii, angle=22.5, **kwargs):
30173020
"""
30183021
Set the radial grid labels at radial distances in radii along
30193022
the radius at angle
@@ -3041,7 +3044,7 @@ def set_rgridlabels(self, radii, angle=67.5, **kwargs):
30413044

30423045
def has_data(self):
30433046
'return true if any artists have been added to axes'
3044-
return len(self.lines)
3047+
return len(self.lines)+len(self.collections)
30453048

30463049
def set_xlabel(self, xlabel, fontdict=None, **kwargs):
30473050
'xlabel not implemented'

lib/matplotlib/matlab.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
imshow - plot image data
4343
pcolor - make a pseudocolor plot
4444
plot - make a line plot
45+
polar - make a polar plot on a PolarAxes
4546
psd - make a plot of power spectral density
4647
rc - control the default params
4748
savefig - save the current figure
@@ -294,7 +295,7 @@ def get_plot_commands(): return ( 'axes', 'axis', 'bar', 'cla', 'clf',
294295
'imshow', 'legend', 'loglog', 'rc', 'pcolor', 'plot', 'psd',
295296
'savefig', 'scatter', 'set', 'semilogx', 'semilogy', 'show',
296297
'specgram', 'stem', 'subplot', 'table', 'text', 'title', 'xlabel',
297-
'ylabel')
298+
'ylabel', 'polar')
298299

299300
def raise_msg_to_str(msg):
300301
"""msg is a return arg from a raise. Join with new lines"""
@@ -1215,5 +1216,4 @@ def polar(*args, **kwargs):
12151216

12161217

12171218
ax = gca(polar=True)
1218-
print 'polar got', ax
12191219
return ax.plot(*args, **kwargs)

src/_backend_agg.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ RendererAgg::draw_poly_collection(const Py::Tuple& args) {
359359
theRasterizer->reset_clipping();
360360

361361
_VERBOSE("RendererAgg::draw_poly_collection");
362+
362363
args.verify_length(9);
363364

364365

@@ -490,6 +491,7 @@ RendererAgg::draw_poly_collection(const Py::Tuple& args) {
490491
g = Py::Float(rgba[1]);
491492
b = Py::Float(rgba[2]);
492493
a = Py::Float(rgba[3]);
494+
493495
if (a>0) { //only render if alpha>0
494496
agg::rgba edgecolor(r, g, b, a);
495497

0 commit comments

Comments
 (0)