File: logo.py

package info (click to toggle)
python-cartopy 0.21.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 14,668 kB
  • sloc: python: 15,101; makefile: 166; javascript: 66; sh: 6
file content (47 lines) | stat: -rw-r--r-- 1,452 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
Cartopy Logo
------------

The actual code to produce cartopy's logo.

"""
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import matplotlib.textpath
import matplotlib.patches
import matplotlib.transforms
from matplotlib.font_manager import FontProperties


def main():
    fig = plt.figure(figsize=[12, 6])
    ax = fig.add_subplot(1, 1, 1, projection=ccrs.Robinson())

    ax.coastlines()
    ax.gridlines()

    # generate a matplotlib path representing the word "cartopy"
    fp = FontProperties(family='DejaVu Sans', weight='bold')
    logo_path = matplotlib.textpath.TextPath((-175, -35), 'cartopy',
                                             size=80, prop=fp)
    # scale the letters up to sensible longitude and latitude sizes
    transform = matplotlib.transforms.Affine2D().scale(1, 2).translate(0, 35)

    # add a background image
    im = ax.stock_img()
    # Apply the scale transform and then the map coordinate transform
    plate_carree_transform = (transform +
                              ccrs.PlateCarree()._as_mpl_transform(ax))

    # add the path as a patch, drawing black outlines around the text
    patch = matplotlib.patches.PathPatch(logo_path,
                                         facecolor='none', edgecolor='black',
                                         transform=plate_carree_transform)
    im.set_clip_path(patch)
    ax.add_patch(patch)

    plt.show()


if __name__ == '__main__':
    main()