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

Function PyplotRadarChart

DemoPrograms/Demo_Matplotlib_Browser_Paned.py:434–618  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

432
433
434def PyplotRadarChart():
435 import numpy as np
436
437 import matplotlib.pyplot as plt
438 from matplotlib.path import Path
439 from matplotlib.spines import Spine
440 from matplotlib.projections.polar import PolarAxes
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"""

Callers

nothing calls this directly

Calls 6

set_titleMethod · 0.80
radar_factoryFunction · 0.70
example_dataFunction · 0.70
plotMethod · 0.45
fillMethod · 0.45
set_varlabelsMethod · 0.45

Tested by

no test coverage detected