Coverage for pyguymer3/geo/_add_background.py: 10%

10 statements  

« prev     ^ index     » next       coverage.py v7.9.2, created at 2025-07-08 18:47 +0000

1#!/usr/bin/env python3 

2 

3# Define function ... 

4def _add_background( 

5 ax, 

6 /, 

7 *, 

8 debug = __debug__, 

9): 

10 """Add background to a Cartopy axis. 

11 

12 Parameters 

13 ---------- 

14 axis : cartopy.mpl.geoaxes.GeoAxesSubplot 

15 the axis to add the background to 

16 debug : bool, optional 

17 print debug messages 

18 

19 Notes 

20 ----- 

21 This function uses `CSS4 named colours 

22 <https://matplotlib.org/stable/gallery/color/named_colors.html>`_ . 

23 

24 Copyright 2017 Thomas Guymer [1]_ 

25 

26 References 

27 ---------- 

28 .. [1] PyGuymer3, https://github.com/Guymer/PyGuymer3 

29 """ 

30 

31 # Import special modules ... 

32 try: 

33 import matplotlib 

34 matplotlib.rcParams.update( 

35 { 

36 "backend" : "Agg", # NOTE: See https://matplotlib.org/stable/gallery/user_interfaces/canvasagg.html 

37 "figure.dpi" : 300, 

38 "figure.figsize" : (9.6, 7.2), # NOTE: See https://github.com/Guymer/misc/blob/main/README.md#matplotlib-figure-sizes 

39 "font.size" : 8, 

40 } 

41 ) 

42 except: 

43 raise Exception("\"matplotlib\" is not installed; run \"pip install --user matplotlib\"") from None 

44 

45 # ************************************************************************** 

46 

47 # Create suitable colour ... 

48 facecolor = matplotlib.colors.to_rgba(matplotlib.colors.CSS4_COLORS["lightblue"]) 

49 if debug: 

50 print(f"INFO: \"background\" is ({facecolor[0]:.6f},{facecolor[1]:.6f},{facecolor[2]:.6f},{facecolor[3]:.6f}).") 

51 

52 # Set background ... 

53 ax.set_facecolor(facecolor)