0

Wanted to add a colorbar to the plot, but get the following error :

AttributeError: 'AxesSubplot' object has no attribute 'get_array'

Code is a bit long, but below is a snippet.

    pitch = Pitch(pitch_type='statsbomb', orientation='horizontal',
                  pitch_color='#000000', line_color='#5c5c5c', figsize=(16, 11),
                  tight_layout=True, goal_type='box')
    fig, ax = pitch.draw()
    img = sns.scatterplot(x='vertical', y='horizontal', data=game_data, hue='PV', s=markersize, 
                          marker=markerstyle, legend=False, palette=color_palette, 
                          linewidth=markeredgewidth, ax=ax)
    fig.colorbar(img, ax=ax)

Colorbar to be added on the side or bottom

Wanted to add the colorbar on the side

Could anyone help? Thanks

  • I find [this answer](https://stackoverflow.com/questions/62884183/trying-to-add-a-colorbar-to-a-seaborn-scatterplot) to be very helpful – r-beginners Mar 14 '21 at 12:28
  • You need to create a `ScalarMappable` from the palette and a norm that uses the min and max of `gamedata['PV']` – JohanC Mar 14 '21 at 16:12

0 Answers0