Skip to content

Commit f118949

Browse files
author
James Evans
committed
Added keyword arguments 'thetaunits' and 'runits' for polar plots.
Fixed PolarAxes so that when it set default Formatters, it marked them as such. Fixed semilogx and semilogy to no longer blindly reset the ticker information on the non-log axis. Axes.arrow can now accept unitized data. svn path=/trunk/matplotlib/; revision=8624
1 parent d732194 commit f118949

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

CHANGELOG

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2010-08-05 Added keyword arguments 'thetaunits' and 'runits' for polar
2+
plots. Fixed PolarAxes so that when it set default
3+
Formatters, it marked them as such. Fixed semilogx and
4+
semilogy to no longer blindly reset the ticker information
5+
on the non-log axis. Axes.arrow can now accept unitized
6+
data. - JRE
7+
18
2010-08-03 Add support for MPLSETUPCFG variable for custom setup.cfg
29
filename. Used by sage buildbot to build an mpl w/ no gui
310
support - JDH

lib/matplotlib/axes.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,11 @@ def __call__(self, *args, **kwargs):
178178

179179
if self.axes.xaxis is not None and self.axes.yaxis is not None:
180180
xunits = kwargs.pop( 'xunits', self.axes.xaxis.units)
181+
if self.axes.name == 'polar':
182+
xunits = kwargs.pop( 'thetaunits', xunits )
181183
yunits = kwargs.pop( 'yunits', self.axes.yaxis.units)
184+
if self.axes.name == 'polar':
185+
yunits = kwargs.pop( 'runits', yunits )
182186
if xunits!=self.axes.xaxis.units:
183187
self.axes.xaxis.set_units(xunits)
184188
if yunits!=self.axes.yaxis.units:
@@ -1554,6 +1558,8 @@ def _process_unit_info(self, xdata=None, ydata=None, kwargs=None):
15541558
# process kwargs 2nd since these will override default units
15551559
if kwargs is not None:
15561560
xunits = kwargs.pop( 'xunits', self.xaxis.units)
1561+
if self.name == 'polar':
1562+
xunits = kwargs.pop( 'thetaunits', xunits )
15571563
if xunits!=self.xaxis.units:
15581564
#print '\tkw setting xunits', xunits
15591565
self.xaxis.set_units(xunits)
@@ -1563,6 +1569,8 @@ def _process_unit_info(self, xdata=None, ydata=None, kwargs=None):
15631569
self.xaxis.update_units(xdata)
15641570

15651571
yunits = kwargs.pop('yunits', self.yaxis.units)
1572+
if self.name == 'polar':
1573+
yunits = kwargs.pop( 'runits', yunits )
15661574
if yunits!=self.yaxis.units:
15671575
#print '\tkw setting yunits', yunits
15681576
self.yaxis.set_units(yunits)
@@ -3953,7 +3961,6 @@ def semilogx(self, *args, **kwargs):
39533961
}
39543962

39553963
self.set_xscale('log', **d)
3956-
self.set_yscale('linear')
39573964
b = self._hold
39583965
self._hold = True # we've already processed the hold
39593966
l = self.plot(*args, **kwargs)
@@ -4004,7 +4011,6 @@ def semilogy(self, *args, **kwargs):
40044011
'nonposy': kwargs.pop('nonposy', 'mask'),
40054012
}
40064013
self.set_yscale('log', **d)
4007-
self.set_xscale('linear')
40084014
b = self._hold
40094015
self._hold = True # we've already processed the hold
40104016
l = self.plot(*args, **kwargs)
@@ -6286,6 +6292,13 @@ def arrow(self, x, y, dx, dy, **kwargs):
62866292
62876293
.. plot:: mpl_examples/pylab_examples/arrow_demo.py
62886294
"""
6295+
# Strip away units for the underlying patch since units
6296+
# do not make sense to most patch-like code
6297+
x = self.convert_xunits(x)
6298+
y = self.convert_yunits(y)
6299+
dx = self.convert_xunits(dx)
6300+
dy = self.convert_yunits(dy)
6301+
62896302
a = mpatches.FancyArrow(x, y, dx, dy, **kwargs)
62906303
self.add_artist(a)
62916304
return a

lib/matplotlib/projections/polar.py

+1
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ def cla(self):
220220
self.title.set_y(1.05)
221221

222222
self.xaxis.set_major_formatter(self.ThetaFormatter())
223+
self.xaxis.isDefault_majfmt = True
223224
angles = np.arange(0.0, 360.0, 45.0)
224225
self.set_thetagrids(angles)
225226
self.yaxis.set_major_locator(self.RadialLocator(self.yaxis.get_major_locator()))

lib/matplotlib/testing/jpl_units/UnitDblConverter.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,7 @@ def axisinfo( unit, axis ):
7979
else:
8080
label = None
8181

82-
if ( label == "rad" ):
83-
# If the axis units are in radians, then use a special function for
84-
# applying format control.
85-
majfmt = ticker.FuncFormatter( rad_fn )
86-
elif ( label == "deg" ) and isinstance( axis.axes, polar.PolarAxes ):
82+
if ( label == "deg" ) and isinstance( axis.axes, polar.PolarAxes ):
8783
# If we want degrees for a polar plot, use the PolarPlotFormatter
8884
majfmt = polar.PolarAxes.ThetaFormatter()
8985
else:

lib/matplotlib/tests/test_axes.py

+8
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,12 @@ def test_polar_wrap():
279279
@image_comparison(baseline_images=['polar_units'])
280280
def test_polar_units():
281281
import matplotlib.testing.jpl_units as units
282+
from nose.tools import assert_true
282283
units.register()
283284

284285
pi = np.pi
285286
deg = units.UnitDbl( 1.0, "deg" )
287+
km = units.UnitDbl( 1.0, "km" )
286288

287289
x1 = [ pi/6.0, pi/4.0, pi/3.0, pi/2.0 ]
288290
x2 = [ 30.0*deg, 45.0*deg, 60.0*deg, 90.0*deg ]
@@ -299,6 +301,12 @@ def test_polar_units():
299301

300302
fig.savefig( 'polar_units' )
301303

304+
# make sure runits and theta units work
305+
y1 = [ y*km for y in y1 ]
306+
plt.polar( x2, y1, color = "blue", thetaunits="rad", runits="km" )
307+
assert_true( isinstance(plt.gca().get_xaxis().get_major_formatter(), units.UnitDblFormatter) )
308+
309+
302310
@image_comparison(baseline_images=['polar_rmin'])
303311
def test_polar_rmin():
304312
r = np.arange(0, 3.0, 0.01)

0 commit comments

Comments
 (0)