8000 fix radar chart gridlines for non-circular charts · matplotlib/matplotlib@f4f33f9 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f4f33f9

Browse files
committed
fix radar chart gridlines for non-circular charts
1 parent f3a2d41 commit f4f33f9

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

examples/specialty_plots/radar_chart.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,22 @@ def radar_factory(num_vars, frame='circle'):
4242
# calculate evenly-spaced axis angles
4343
theta = np.linspace(0, 2*np.pi, num_vars, endpoint=False)
4444

45+
class RadarTransform(PolarAxes.PolarTransform):
46+
47+
def transform_path_non_affine(self, path):
48+
# Paths with non-unit interpolation steps correspond to gridlines,
49+
# in which case we force interpolation (to defeat PolarTransform's
50+
# autoconversion to circular arcs).
51+
if path._interpolation_steps > 1:
52+
path = path.interpolated(num_vars)
53+
return Path(self.transform(path.vertices), path.codes)
54+
4555
class RadarAxes(PolarAxes):
4656

4757
name = 'radar'
4858
# use 1 line segment to connect specified points
4959
RESOLUTION = 1
60+
PolarTransform = RadarTransform
5061

5162
def __init__(self, *args, **kwargs):
5263
super().__init__(*args, **kwargs)
@@ -175,7 +186,7 @@ def example_data():
175186
horizontalalignment='center', verticalalignment='center')
176187
for d, color in zip(case_data, colors):
177188
ax.plot(theta, d, color=color)
178-
ax.fill(theta, d, facecolor=color, alpha=0.25)
189+
ax.fill(theta, d, facecolor=color, alpha=0.25, label='_nolegend_')
179190
ax.set_varlabels(spoke_labels)
180191

181192
# add legend relative to top-left plot

0 commit comments

Comments
 (0)
0