Skip to content
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

Avoid changing background colors in radar chart #50

Closed
darinkist opened this issue Jun 11, 2022 · 2 comments
Closed

Avoid changing background colors in radar chart #50

darinkist opened this issue Jun 11, 2022 · 2 comments

Comments

@darinkist
Copy link

darinkist commented Jun 11, 2022

Hi,

when I create a simple radar cart:

from mplsoccer.radar_chart import Radar

## parameter names
params = ['xAssist', 'Key Passes', 'Crosses Into Box', 'Cross Completion %', 'Deep Completions',
          'Progressive Passes', 'Prog. Pass Accuracy', 'Dribbles', 'Progressive Runs',
          'PADJ Interceptions', 'Succ. Def. Actions', 'Def Duel Win %']

## range values
ranges = [(0.0, 0.15), (0.0, 0.67), (0.06, 6.3), (19.51, 50.0), (0.35, 1.61),
          (6.45, 11.94), (62.9, 79.4), (0.43, 4.08), (0.6, 2.33),
          (4.74, 7.2), (8.59, 12.48), (50.66, 66.67)]

min_range = [0.0,0.0,0.06,19.51,0.35,6.45,62.9,0.43,0.6,4.74,8.59,50.66]
max_range = [0.15, 0.67, 6.3, 50.0,1.61,11.94,79.4,4.08,2.33,7.2,12.48,66.67]

## parameter value
values = [0.11, 0.53, 0.70, 27.66, 1.05, 6.84, 84.62, 4.56, 2.22, 5.93, 8.88, 64.29]


## instantiate object
radar = Radar(params, min_range, max_range)

fig, ax = radar.setup_axis()  # format axis as a radar
rings_inner = radar.draw_circles(ax=ax, facecolor='#ffffff', edgecolor='#000000')  # draw circles
radar_output = radar.draw_radar(values, ax=ax,
                                kwargs_radar={'facecolor': '#709775','alpha': 0.8},
                                kwargs_rings={'facecolor': '#709775', 'alpha':0.8})  # draw the radar

range_labels = radar.draw_range_labels(ax=ax, fontsize=8)
param_labels = radar.draw_param_labels(ax=ax, fontsize=12, **{'color':'#ffffff'})  # draw the param labels

I get the following visualization where (depending on the ring) the color of the polygon is lighter or darker green:
Download (3)
Is there a way to avoid the changing colors of the polygon for every ring?

@darinkist
Copy link
Author

Nevermind... found my mistake. One can solve it by using the following code:

from mplsoccer.radar_chart import Radar

## parameter names
params = ['xAssist', 'Key Passes', 'Crosses Into Box', 'Cross Completion %', 'Deep Completions',
          'Progressive Passes', 'Prog. Pass Accuracy', 'Dribbles', 'Progressive Runs',
          'PADJ Interceptions', 'Succ. Def. Actions', 'Def Duel Win %']

## range values
ranges = [(0.0, 0.15), (0.0, 0.67), (0.06, 6.3), (19.51, 50.0), (0.35, 1.61),
          (6.45, 11.94), (62.9, 79.4), (0.43, 4.08), (0.6, 2.33),
          (4.74, 7.2), (8.59, 12.48), (50.66, 66.67)]

min_range = [0.0,0.0,0.06,19.51,0.35,6.45,62.9,0.43,0.6,4.74,8.59,50.66]
max_range = [0.15, 0.67, 6.3, 50.0,1.61,11.94,79.4,4.08,2.33,7.2,12.48,66.67]

## parameter value
values = [0.11, 0.53, 0.70, 27.66, 1.05, 6.84, 84.62, 4.56, 2.22, 5.93, 8.88, 64.29]


## instantiate object
radar = Radar(params, min_range, max_range)

fig, ax = radar.setup_axis()  # format axis as a radar
rings_inner = radar.draw_circles(ax=ax, facecolor='#ffffff', edgecolor='#000000')  # draw circles
radar_output = radar.draw_radar(values, ax=ax,
                                kwargs_radar={'facecolor': '#709775','alpha': 0.8},
                                kwargs_rings={'facecolor': '#709775', 'alpha':0.0})  # draw the radar

range_labels = radar.draw_range_labels(ax=ax, fontsize=8)
param_labels = radar.draw_param_labels(ax=ax, fontsize=12, **{'color':'#ffffff'})  # draw the param labels

@andrewRowlinson
Copy link
Owner

Nice thanks for posting the solution. 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants