Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 06e389f

Browse files
authored
Merge pull request #4699 from QuLogic/polar-limits
Polar limits enhancements
2 parents 2ed56ab + 7b998e1 commit 06e389f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+21353
-16774
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Enhancements to polar plot
2+
--------------------------
3+
4+
The polar axes transforms have been greatly re-factored to allow for more
5+
customization of view limits and tick labelling. Additional options for view
6+
limits allow for creating an annulus, a sector, or some combination of the two.
7+
8+
The :meth:`~matplotlib.axes.projections.polar.PolarAxes.set_rorigin` method may
9+
be used to provide an offset to the minimum plotting radius, producing an
10+
annulus.
11+
12+
The :meth:`~matplotlib.projections.polar.PolarAxes.set_theta_zero_location` now
13+
has an optional :code:`offset` argument. This argument may be used to further
14+
specify the zero location based on the given anchor point.
15+
16+
.. figure:: ../../gallery/pie_and_polar_charts/images/sphx_glr_polar_scatter_001.png
17+
:target: ../../gallery/pie_and_polar_charts/polar_scatter.html
18+
:align: center
19+
:scale: 50
20+
21+
Polar Offset Demo
22+
23+
The :meth:`~matplotlib.axes.projections.polar.PolarAxes.set_thetamin` and
24+
:meth:`~matplotlib.axes.projections.polar.PolarAxes.set_thetamax` methods may
25+
be used to limit the range of angles plotted, producing sectors of a circle.
26+
27+
.. figure:: ../../gallery/pie_and_polar_charts/images/sphx_glr_polar_scatter_002.png
28+
:target: ../../gallery/pie_and_polar_charts/polar_scatter.html
29+
:align: center
30+
:scale: 50
31+
32+
Polar Sector Demo
33+
34+
Previous releases allowed plots containing negative radii for which the
35+
negative values are simply used as labels, and the real radius is shifted by
36+
the configured minimum. This release also allows negative radii to be used for
37+
grids and ticks, which were previously silently ignored.

examples/api/radar_chart.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,10 @@ def radar_factory(num_vars, frame='circle'):
3737
"""
3838
# calculate evenly-spaced axis angles
3939
theta = np.linspace(0, 2*np.pi, num_vars, endpoint=False)
40-
# rotate theta such that the first axis is at the top
41-
theta += np.pi/2
4240

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

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

62+
def __init__(self, *args, **kwargs):
63+
super(RadarAxes, self).__init__(*args, **kwargs)
64+
# rotate plot such that the first axis is at the top
65+
self.set_theta_zero_location('N')
66+
6367
def fill(self, *args, **kwargs):
6468
"""Override fill so that line is closed by default"""
6569
closed = kwargs.pop('closed', True)
@@ -93,7 +97,7 @@ def _gen_axes_spines(self):
9397

9498
# spine_type must be 'left', 'right', 'top', 'bottom', or `circle`.
9599
spine_type = 'circle'
96-
verts = unit_poly_verts(theta)
100+
verts = unit_poly_verts(theta + np.pi / 2)
97101
# close off polygon by repeating first vertex
98102
verts.append(verts[0])
99103
path = Path(verts)

examples/pie_and_polar_charts/polar_scatter.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
Scatter plot on polar axis
44
==========================
55
6-
Demo of scatter plot on a polar axis.
7-
86
Size increases radially in this example and color increases with angle
97
(just to verify the symbols are being scattered correctly).
108
"""
@@ -22,7 +20,37 @@
2220
area = 200 * r**2
2321
colors = theta
2422

25-
ax = plt.subplot(111, projection='polar')
23+
fig = plt.figure()
24+
ax = fig.add_subplot(111, projection='polar')
2625
c = ax.scatter(theta, r, c=colors, s=area, cmap='hsv', alpha=0.75)
2726

27+
###############################################################################
28+
# Scatter plot on polar axis, with offset origin
29+
# ----------------------------------------------
30+
#
31+
# The main difference with the previous plot is the configuration of the origin
32+
# radius, producing an annulus. Additionally, the theta zero location is set to
33+
# rotate the plot.
34+
35+
fig = plt.figure()
36+
ax = fig.add_subplot(111, polar=True)
37+
c = ax.scatter(theta, r, c=colors, s=area, cmap='hsv', alpha=0.75)
38+
39+
ax.set_rorigin(-2.5)
40+
ax.set_theta_zero_location('W', offset=10)
41+
42+
###############################################################################
43+
# Scatter plot on polar axis confined to a sector
44+
# -----------------------------------------------
45+
#
46+
# The main difference with the previous plots is the configuration of the
47+
# theta start and end limits, producing a sector instead of a full circle.
48+
49+
fig = plt.figure()
50+
ax = fig.add_subplot(111, polar=True)
51+
c = ax.scatter(theta, r, c=colors, s=area, cmap='hsv', alpha=0.75)
52+
53+
ax.set_thetamin(45)
54+
ax.set_thetamax(135)
55+
2856
plt.show()

0 commit comments

Comments
 (0)