示例#1
0
    ncols=4,
    space=0.1,
    figheight=40,
    title_height=0,
    endnote_height=0,  # no title/ endnote
    grid_width=0.9,
    grid_height=0.98,
    bottom=0.01,
    left=0.05)
cmap_names = list(all_cmap_dict.keys())
for idx, ax in enumerate(axs['pitch'].flat):
    cmap_name = f'cmr.{cmap_names[idx]}'
    cmap = all_cmap_dict[cmap_names[idx]]
    kdeplot = pitch.kdeplot(df.x,
                            df.y,
                            ax=ax,
                            cmap=cmap,
                            shade=True,
                            levels=100)
    ax.set_title(cmap_name, fontsize=15)

##############################################################################
# Cmasher kdeplot
# ---------------
# I like the look of the voltage colormap so let's plot in against a light and
# dark background
#
# You can reverse any of the colormaps, by putting
# _r at the end, for example cmr.arctic_r (this also applies to matplotlib cmaps).
#
# Reversing the colormaps is sometimes helpful so the high value colors do not bleed into the
# background. I prefer dark to light colormaps on dark background, and light to dark
示例#2
0
##############################################################################
# Create a custom colormap.
# Note see the `custom colormaps
# <https://mplsoccer.readthedocs.io/en/latest/gallery/pitch_plots/plot_cmap.html>`_
# example for more ideas.
flamingo_cmap = LinearSegmentedColormap.from_list("Flamingo - 100 colors",
                                                  ['#e3aca7', '#c03a1d'], N=100)

##############################################################################
# Plot Messi's first game as a false-9.
pitch = VerticalPitch(line_color='#000009', line_zorder=2)
fig, ax = pitch.draw(figsize=(4.4, 6.4))
kde = pitch.kdeplot(df_false9.x, df_false9.y, ax=ax,
                    # shade using 100 levels so it looks smooth
                    shade=True, levels=100,
                    # shade the lowest area so it looks smooth
                    # so even if there are no events it gets some color
                    shade_lowest=True,
                    cut=4,  # extended the cut so it reaches the bottom edge
                    cmap=flamingo_cmap)

##############################################################################
# Load a custom font.
URL = 'https://github.com/googlefonts/roboto/blob/main/src/hinted/Roboto-Regular.ttf?raw=true'
URL2 = 'https://github.com/google/fonts/blob/main/apache/roboto/static/Roboto-Bold.ttf?raw=true'
robotto_regular = FontManager(URL)
robboto_bold = FontManager(URL2)

##############################################################################
# Load images.

# Load the StatsBomb logo and Messi picture