Skip to content

Commit

Permalink
Replace plt.tightlayout with plt.subplots_adjust.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Yeo committed Sep 2, 2020
1 parent 521c713 commit e6a11c9
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions docs/iris/src/sphinxext/generate_logo.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
from xml.etree import ElementTree as ET
from xml.dom import minidom

from cartopy import crs as ccrs, __version__ as cartopy_version
from cartopy import crs as ccrs
from cartopy.feature import LAND
from matplotlib import pyplot as plt, rcParams
from matplotlib import pyplot as plt
from numpy import linspace

print("LOGO GENERATION START ...")
Expand Down Expand Up @@ -50,19 +50,13 @@

################################################################################

# Establish some sizes and ratios.
# Set plot to include space for the mask to be added.
# Establish some sizes and ratios - allows space for the mask to be added after plotting.
# figure_inches doesn't influence the final size, but does influence the coastline definition.
figure_inches = 10
mpl_points_per_inch = 72

globe_inches = figure_inches / CLIP_GLOBE_RATIO
pad_inches = (figure_inches - globe_inches) / 2
globe_pad = (1 - (1 / CLIP_GLOBE_RATIO)) / 2
background_points = figure_inches * mpl_points_per_inch
globe_points = globe_inches * mpl_points_per_inch

mpl_font_points = rcParams["font.size"]
inch_font_ratio = mpl_points_per_inch / mpl_font_points

# XML ElementTree setup.
namespaces = {"svg": "http://www.w3.org/2000/svg"}
Expand Down Expand Up @@ -120,19 +114,16 @@
# Normalise to -180..+180
rotation_longitudes = (rotation_longitudes + 360.0 + 180.0) % 360.0 - 180.0

for lon in rotation_longitudes:
for lon in rotation_longitudes[:2]:
# Use Matplotlib and Cartopy to generate land-shaped SVG clips for each longitude.

projection_rotated = ccrs.Orthographic(central_longitude=lon,
central_latitude=central_latitude)

fig = plt.figure(0, figsize=(figure_inches,) * 2)
ax = plt.axes(projection=projection_rotated)
# TODO: remove version check Iris is pinned appropriately.
if cartopy_version < "0.18":
fig.canvas.draw()
# Use constants set earlier to achieve desired dimensions.
plt.tight_layout(pad=pad_inches * inch_font_ratio)
fig = plt.figure(0, figsize=(figure_inches,) * 2)
ax = plt.subplot(projection=projection_rotated)
plt.subplots_adjust(left=globe_pad, bottom=globe_pad, right=1 - globe_pad, top=1 - globe_pad)
ax.add_feature(LAND)

# Save as SVG and extract the resultant code.
Expand Down

0 comments on commit e6a11c9

Please sign in to comment.