MCPcopy Index your code
hub / github.com/PySimpleGUI/PySimpleGUI / radar_factory

Function radar_factory

DemoPrograms/Demo_Matplotlib_Browser_Paned.py:443–528  ·  view source on GitHub ↗

Create a radar chart with `num_vars` axes. This function creates a RadarAxes projection and registers it. Parameters ---------- num_vars : int Number of variables for radar chart. frame : {'circle' | 'polygon'} Shape of frame surround

(num_vars, frame='circle')

Source from the content-addressed store, hash-verified

441 from matplotlib.projections import register_projection
442
443 def radar_factory(num_vars, frame='circle'):
444 """Create a radar chart with `num_vars` axes.
445
446 This function creates a RadarAxes projection and registers it.
447
448 Parameters
449 ----------
450 num_vars : int
451 Number of variables for radar chart.
452 frame : {'circle' | 'polygon'}
453 Shape of frame surrounding axes.
454
455 """
456 # calculate evenly-spaced axis angles
457 theta = np.linspace(0, 2 * np.pi, num_vars, endpoint=False)
458
459 def draw_poly_patch(self):
460 # rotate theta such that the first axis is at the top
461 verts = unit_poly_verts(theta + np.pi / 2)
462 return plt.Polygon(verts, closed=True, edgecolor='k')
463
464 def draw_circle_patch(self):
465 # unit circle centered on (0.5, 0.5)
466 return plt.Circle((0.5, 0.5), 0.5)
467
468 patch_dict = {'polygon': draw_poly_patch, 'circle': draw_circle_patch}
469 if frame not in patch_dict:
470 raise ValueError('unknown value for `frame`: %s' % frame)
471
472 class RadarAxes(PolarAxes):
473
474 name = 'radar'
475 # use 1 line segment to connect specified points
476 RESOLUTION = 1
477 # define draw_frame method
478 draw_patch = patch_dict[frame]
479
480 def __init__(self, *args, **kwargs):
481 super(RadarAxes, self).__init__(*args, **kwargs)
482 # rotate plot such that the first axis is at the top
483 self.set_theta_zero_location('N')
484
485 def fill(self, *args, **kwargs):
486 """Override fill so that line is closed by default"""
487 closed = kwargs.pop('closed', True)
488 return super(RadarAxes, self).fill(closed=closed, *args, **kwargs)
489
490 def plot(self, *args, **kwargs):
491 """Override plot so that line is closed by default"""
492 lines = super(RadarAxes, self).plot(*args, **kwargs)
493 for line in lines:
494 self._close_line(line)
495
496 def _close_line(self, line):
497 x, y = line.get_data()
498 # FIXME: markers at x[0], y[0] get doubled-up
499 if x[0] != x[-1]:
500 x = np.concatenate((x, [x[0]]))

Callers 1

PyplotRadarChartFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected