Skip to content

Polar limits enhancements #4699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Aug 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions doc/users/next_whats_new/2015-10-31_polar_limits.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Enhancements to polar plot
--------------------------

The polar axes transforms have been greatly re-factored to allow for more
customization of view limits and tick labelling. Additional options for view
limits allow for creating an annulus, a sector, or some combination of the two.

The :meth:`~matplotlib.axes.projections.polar.PolarAxes.set_rorigin` method may
be used to provide an offset to the minimum plotting radius, producing an
annulus.

The :meth:`~matplotlib.projections.polar.PolarAxes.set_theta_zero_location` now
has an optional :code:`offset` argument. This argument may be used to further
specify the zero location based on the given anchor point.

.. figure:: ../../gallery/pie_and_polar_charts/images/sphx_glr_polar_scatter_001.png
:target: ../../gallery/pie_and_polar_charts/polar_scatter.html
:align: center
:scale: 50

Polar Offset Demo

The :meth:`~matplotlib.axes.projections.polar.PolarAxes.set_thetamin` and
:meth:`~matplotlib.axes.projections.polar.PolarAxes.set_thetamax` methods may
be used to limit the range of angles plotted, producing sectors of a circle.

.. figure:: ../../gallery/pie_and_polar_charts/images/sphx_glr_polar_scatter_002.png
:target: ../../gallery/pie_and_polar_charts/polar_scatter.html
:align: center
:scale: 50

Polar Sector Demo

Previous releases allowed plots containing negative radii for which the
negative values are simply used as labels, and the real radius is shifted by
the configured minimum. This release also allows negative radii to be used for
grids and ticks, which were previously silently ignored.
12 changes: 8 additions & 4 deletions examples/api/radar_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ def radar_factory(num_vars, frame='circle'):
"""
# calculate evenly-spaced axis angles
theta = np.linspace(0, 2*np.pi, num_vars, endpoint=False)
# rotate theta such that the first axis is at the top
theta += np.pi/2

def draw_poly_patch(self):
verts = unit_poly_verts(theta)
# rotate theta such that the first axis is at the top
verts = unit_poly_verts(theta + np.pi / 2)
return plt.Polygon(verts, closed=True, edgecolor='k')

def draw_circle_patch(self):
Expand All @@ -60,6 +59,11 @@ class RadarAxes(PolarAxes):
# define draw_frame method
draw_patch = patch_dict[frame]

def __init__(self, *args, **kwargs):
super(RadarAxes, self).__init__(*args, **kwargs)
# rotate plot such that the first axis is at the top
self.set_theta_zero_location('N')

def fill(self, *args, **kwargs):
"""Override fill so that line is closed by default"""
closed = kwargs.pop('closed', True)
Expand Down Expand Up @@ -93,7 +97,7 @@ def _gen_axes_spines(self):

# spine_type must be 'left', 'right', 'top', 'bottom', or `circle`.
spine_type = 'circle'
verts = unit_poly_verts(theta)
verts = unit_poly_verts(theta + np.pi / 2)
# close off polygon by repeating first vertex
verts.append(verts[0])
path = Path(verts)
Expand Down
34 changes: 31 additions & 3 deletions examples/pie_and_polar_charts/polar_scatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
Scatter plot on polar axis
==========================

Demo of scatter plot on a polar axis.

Size increases radially in this example and color increases with angle
(just to verify the symbols are being scattered correctly).
"""
Expand All @@ -22,7 +20,37 @@
area = 200 * r**2
colors = theta

ax = plt.subplot(111, projection='polar')
fig = plt.figure()
ax = fig.add_subplot(111, projection='polar')
c = ax.scatter(theta, r, c=colors, s=area, cmap='hsv', alpha=0.75)

###############################################################################
# Scatter plot on polar axis, with offset origin
# ----------------------------------------------
#
# The main difference with the previous plot is the configuration of the origin
# radius, producing an annulus. Additionally, the theta zero location is set to
# rotate the plot.

fig = plt.figure()
ax = fig.add_subplot(111, polar=True)
c = ax.scatter(theta, r, c=colors, s=area, cmap='hsv', alpha=0.75)

ax.set_rorigin(-2.5)
ax.set_theta_zero_location('W', offset=10)

###############################################################################
# Scatter plot on polar axis confined to a sector
# -----------------------------------------------
#
# The main difference with the previous plots is the configuration of the
# theta start and end limits, producing a sector instead of a full circle.

fig = plt.figure()
ax = fig.add_subplot(111, polar=True)
c = ax.scatter(theta, r, c=colors, s=area, cmap='hsv', alpha=0.75)

ax.set_thetamin(45)
ax.set_thetamax(135)

plt.show()
Loading