Coverage for pySDC / projects / RayleighBenard / analysis_scripts / plotting_utils.py: 100%

8 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-03-27 07:06 +0000

1from functools import partial 

2import warnings 

3import os 

4import matplotlib.pyplot as plt 

5 

6from pySDC.helpers.plot_helper import figsize_by_journal, setup_mpl 

7 

8setup_mpl() 

9plt.rcParams['markers.fillstyle'] = 'none' 

10 

11figsize = partial(figsize_by_journal, journal='Nature_CS') 

12 

13 

14def get_plotting_style(config): # pragma: no cover 

15 

16 args = {'color': None, 'ls': None, 'marker': None, 'markersize': 6, 'label': None} 

17 

18 config_no_Ra = config[: config.index('Ra')] 

19 

20 if config_no_Ra == 'RBC3DG4R4SDC22': 

21 args['color'] = 'tab:brown' 

22 args['ls'] = '-' 

23 args['marker'] = '3' 

24 args['label'] = 'SDC22' 

25 elif config_no_Ra == 'RBC3DG4R4SDC23': 

26 args['color'] = 'tab:blue' 

27 args['ls'] = '-' 

28 args['marker'] = 'o' 

29 args['label'] = 'SDC23' 

30 elif config_no_Ra == 'RBC3DG4R4SDC34': 

31 args['color'] = 'tab:orange' 

32 args['ls'] = '-' 

33 args['marker'] = '<' 

34 args['label'] = 'SDC34' 

35 elif config_no_Ra == 'RBC3DG4R4SDC44': 

36 args['color'] = 'tab:green' 

37 args['ls'] = '-' 

38 args['marker'] = 'x' 

39 args['label'] = 'SDC44' 

40 elif config_no_Ra == 'RBC3DG4R4Euler': 

41 args['color'] = 'tab:purple' 

42 args['ls'] = '--' 

43 args['marker'] = '.' 

44 args['label'] = 'RK111' 

45 elif config_no_Ra == 'RBC3DG4R4RK': 

46 args['color'] = 'tab:red' 

47 args['ls'] = '--' 

48 args['marker'] = '>' 

49 args['label'] = 'RK443' 

50 else: 

51 warnings.warn(f'No plotting style for {config=!r}') 

52 

53 return args 

54 

55 

56def savefig(fig, name, format='pdf', base_path='./plots', **kwargs): # pragma: no cover 

57 from pathlib import Path 

58 

59 abs_base_path = f'{Path(__file__).parent.parent}/{base_path}' 

60 

61 os.makedirs(abs_base_path, exist_ok=True) 

62 

63 path = f'{abs_base_path}/{name}.{format}' 

64 fig.savefig(path, bbox_inches='tight', **kwargs) 

65 print(f'Saved figure {path!r}')