11import matplotlib .pyplot as plt
22from matplotlib .axes import Axes
3- from typing import Union
3+ from typing import Union , Optional
4+
45
56from .preparator import split_dict_evenly
67
@@ -65,7 +66,6 @@ def generate_diagram(
6566 ax .spines ["top" ].set_visible (False )
6667 ax .spines ["left" ].set_visible (False )
6768 ax .spines ["right" ].set_visible (False )
68- # plt.setp(ax.get_xticklabels(), color="w", fontsize=8)
6969 ax .get_xaxis ().set_visible (False )
7070
7171
@@ -79,6 +79,7 @@ def generate_skill_picture(
7979 background_color : _COLOR = DARK_GRAY ,
8080 bar_color : _COLOR = DARK_GRAY ,
8181 font_color : _COLOR = BLUE ,
82+ canvas_color : Optional [_COLOR ] = None ,
8283):
8384 """Generate a bar diagram for the given skills.
8485
@@ -99,7 +100,7 @@ def generate_skill_picture(
99100 # generate the diagram, splits the values into two lists to plot.
100101 # this should be done in the future over one loop
101102 # the loop decides what to put when and how many columns
102- _ , axes = plt .subplots (1 , n_splits , figsize = (10 * n_splits , split_len ))
103+ fig , axes = plt .subplots (1 , n_splits , figsize = (10 * n_splits , split_len ))
103104
104105 # will get an iterable error since when using only one column, axes is not a list
105106 # just put the Axes object into a list to fix this
@@ -108,5 +109,15 @@ def generate_skill_picture(
108109
109110 for ax , skills in zip (axes , split_skills ):
110111 generate_diagram (ax , skills , bar_height , background_height , background_color , bar_color , font_color )
112+ # need also to set face color of each axis
113+ if canvas_color is not None :
114+ ax .set_facecolor (canvas_color )
115+ # set the facecolor of the canvas to the given color
116+ extra_args = {}
117+ if canvas_color is not None :
118+ fig .set_facecolor (canvas_color )
119+ # only transparent if there is no canvas color
120+ else :
121+ extra_args ["transparent" ] = True
111122 plt .tight_layout ()
112- plt .savefig (f"{ save_name } .{ file_type } " , format = file_type , transparent = True )
123+ plt .savefig (f"{ save_name } .{ file_type } " , format = file_type , ** extra_args )
0 commit comments