8000 Use custom *Axis in polar plots. · matplotlib/matplotlib@73e4425 · GitHub
[go: up one dir, main page]

Skip to content

Commit 73e4425

Browse files
committed
Use custom *Axis in polar plots.
1 parent 6ec497a commit 73e4425

File tree

1 file changed

+67
-13
lines changed

1 file changed

+67
-13
lines changed

lib/matplotlib/projections/polar.py

Lines changed: 67 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,39 @@ def zoom(self, direction):
240240
return self.base.zoom(direction)
241241

242242

243+
class ThetaAxis(maxis.XAxis):
244+
"""
245+
A theta Axis.
246+
247+
This overrides certain properties of an `XAxis` to provide special-casing
248+
for an angular axis.
249+
"""
250+
__name__ = 'thetaaxis'
251+
axis_name = 'theta'
252+
253+
def _get_tick(self, major):
254+
if major:
255+
tick_kw = self._major_tick_kw
256+
else:
257+
tick_kw = self._minor_tick_kw
258+
return maxis.XTick(self.axes, 0, '', major=major, **tick_kw)
259+
260+
def _wrap_locator_formatter(self):
261+
self.set_major_locator(ThetaLocator(self.get_major_locator()))
262+
self.set_major_formatter(ThetaFormatter())
263+
self.isDefault_majloc = True
264+
self.isDefault_majfmt = True
265+
266+
def cla(self):
267+
maxis.XAxis.cla(self)
268+
self.set_ticks_position('none')
269+
self._wrap_locator_formatter()
270+
271+
def _set_scale(self, value, **kwargs):
272+
maxis.XAxis._set_scale(self, value, **kwargs)
273+
self._wrap_locator_formatter()
274+
275+
243276
class RadialLocator(mticker.Locator):
244277
"""
245278
Used to locate radius ticks.
@@ -284,6 +317,38 @@ def view_limits(self, vmin, vmax):
284317
return mtransforms.nonsingular(min(0, vmin), vmax)
285318

286319

320+
class RadialAxis(maxis.YAxis):
321+
"""
322+
A radial Axis.
323+
324+
This overrides certain properties of a `YAxis` to provide special-casing
325+
for a radial axis.
326+
"""
327+
__name__ = 'radialaxis'
328+
axis_name = 'radius'
329+
330+
def _get_tick(self, major):
331+
if major:
332+
tick_kw = self._major_tick_kw
333+
else:
334+
tick_kw = self._minor_tick_kw
335+
return maxis.YTick(self.axes, 0, '', major=major, **tick_kw)
336+
337+
def _wrap_locator_formatter(self):
338+
self.set_major_locator(RadialLocator(self.get_major_locator(),
339+
self.axes))
340+
self.isDefault_majloc = True
341+
342+
def cla(self):
343+
maxis.YAxis.cla(self)
344+
self.set_ticks_position('none')
345+
self._wrap_locator_formatter()
346+
347+
def _set_scale(self, value, **kwargs):
348+
maxis.YAxis._set_scale(self, value, **kwargs)
349+
self._wrap_locator_formatter()
350+
351+
287352
def _is_full_circle_deg(thetamin, thetamax):
288353
"""
289354
Determine if a wedge (in degrees) spans the full circle.
@@ -397,38 +462,27 @@ def cla(self):
397462

398463
self.title.set_y(1.05)
399464

400-
self.xaxis.set_major_formatter(self.ThetaFormatter())
401-
self.xaxis.isDefault_majfmt = True
402465
start = self.spines.get('start', None)
403466
if start:
404467
start.set_visible(False)
405468
end = self.spines.get('end', None)
406469
if end:
407470
end.set_visible(False)
408471
self.set_xlim(0.0, 2 * np.pi)
409-
self.xaxis.set_major_locator(
410-
self.ThetaLocator(self.xaxis.get_major_locator()))
411472

412473
self.grid(rcParams['polaraxes.grid'])
413-
self.xaxis.set_ticks_position('none')
414474
inner = self.spines.get('inner', None)
415475
if inner:
416476
inner.set_visible(False)
417-
self.yaxis.set_ticks_position('none')
418-
# Why do we need to turn on yaxis tick labels, but
419-
# xaxis tick labels are already on?
420-
self.yaxis.set_tick_params(label1On=True)
421-
self.yaxis.set_major_locator(
422-
self.RadialLocator(self.yaxis.get_major_locator(), self))
423477

424478
self.set_rorigin(None)
425479
self.set_theta_offset(self._default_theta_offset)
426480
self.set_theta_direction(self._default_theta_direction)
427481

428482
def _init_axis(self):
429483
"move this out of __init__ because non-separable axes don't use it"
430-
self.xaxis = maxis.XAxis(self)
431-
self.yaxis = maxis.YAxis(self)
484+
self.xaxis = ThetaAxis(self)
485+
self.yaxis = RadialAxis(self)
432486
# Calling polar_axes.xaxis.cla() or polar_axes.xaxis.cla()
433487
# results in weird artifacts. Therefore we disable this for
434488
# now.

0 commit comments

Comments
 (0)
0