55import sys
66import warnings
77from pathlib import Path
8- from typing import Tuple
8+ from typing import Any , Dict , Tuple
99
1010import matplotlib .pyplot as plt
1111from matplotlib .axes import Axes
12+ from matplotlib .figure import Figure
1213
1314
1415def create_example_plots (
@@ -39,7 +40,7 @@ def create_example_plots(
3940 return
4041
4142 # Define a fallback theme in case no configuration is found
42- fallback = {
43+ fallback : Dict [ str , Any ] = {
4344 "color" : "black" ,
4445 "figsize" : (24 , 8 ),
4546 "fontsize" : 22 ,
@@ -100,7 +101,11 @@ def create_example_plots(
100101 ax .yaxis .label .set_fontsize (fontsize )
101102
102103 # Adjust the size of the ax
103- ax .figure .set_size_inches (* figsize )
104+ # mypy thinks that ax.figure might become None, hence the explicit ignore
105+ if isinstance (ax .figure , Figure ):
106+ ax .figure .set_size_inches (* figsize )
107+ else :
108+ warnings .warn ("Could not adjust size of plot due to it not being a Figure." )
104109
105110 # Adjust the labels
106111 for label in ax .get_xticklabels () + ax .get_yticklabels ():
@@ -117,9 +122,13 @@ def create_example_plots(
117122 text .set_color (color )
118123
119124 output_path = Path (path , f"{ base_name } _{ theme_name } .svg" )
120- ax .figure .savefig (
121- output_path ,
122- format = "svg" ,
123- transparent = True ,
124- )
125+ # mypy thinks that ax.figure might become None, hence the explicit ignore
126+ if isinstance (ax .figure , Figure ):
127+ ax .figure .savefig (
128+ output_path ,
129+ format = "svg" ,
130+ transparent = True ,
131+ )
132+ else :
133+ warnings .warn ("Plots could not be saved." )
125134 plt .close ()
0 commit comments