@@ -30,6 +30,8 @@ def _master_plot(
30
30
dpi : float = "figure" ,
31
31
data_labels : list = [],
32
32
axis_padding : float = 0.5 ,
33
+ xy_lim : list = [],
34
+ font_sizes : dict = {"title" : 12 , "labels" : 9 , "other" : 12 },
33
35
):
34
36
"""Handles the aesthetics of the plots in one place.
35
37
@@ -81,26 +83,34 @@ def _master_plot(
81
83
list of labels for each data point
82
84
axis_padding : float, default = 0.5
83
85
padding to add to maximum axis value and subtract from the minimum axis value
86
+ xy_lim : list, default []
87
+ contains the minimium and maximum values to use for the x and y axes. if specified, axis_padding is ignored
88
+ font_sizes : dict, default {"title": 12, "labels": 9, "other": 12}
89
+ font sizes to use for the title ("title"), the data labels ("labels"), and the rest of the plot ("other")
84
90
85
91
Returns
86
92
-------
87
93
88
94
"""
89
95
nsamples = len (x )
90
96
# aesthetics
91
- plt .rcParams ["xtick.labelsize" ] = 12
92
- plt .rcParams ["ytick.labelsize" ] = 12
93
- plt .rcParams ["font.size" ] = 12
97
+ plt .rcParams ["xtick.labelsize" ] = font_sizes [ "other" ]
98
+ plt .rcParams ["ytick.labelsize" ] = font_sizes [ "other" ]
99
+ plt .rcParams ["font.size" ] = font_sizes [ "other" ]
94
100
95
101
fig = plt .figure (figsize = (figsize , figsize ))
96
102
plt .subplots_adjust (left = 0.2 , right = 0.8 , bottom = 0.2 , top = 0.8 )
97
103
98
104
plt .xlabel (f"{ xlabel } { quantity } ({ units } )" )
99
105
plt .ylabel (f"{ ylabel } { quantity } ({ units } )" )
100
106
101
- ax_min = min (min (x ), min (y )) - axis_padding
102
- ax_max = max (max (x ), max (y )) + axis_padding
103
- scale = [ax_min , ax_max ]
107
+ if xy_lim :
108
+ ax_min , ax_max = xy_lim
109
+ scale = xy_lim
110
+ else :
111
+ ax_min = min (min (x ), min (y )) - axis_padding
112
+ ax_max = max (max (x ), max (y )) + axis_padding
113
+ scale = [ax_min , ax_max ]
104
114
105
115
plt .xlim (scale )
106
116
plt .ylim (scale )
@@ -151,7 +161,7 @@ def _master_plot(
151
161
# Label points
152
162
texts = []
153
163
for i , label in enumerate (data_labels ):
154
- texts .append (plt .text (x [i ] + 0.03 , y [i ] + 0.03 , label , fontsize = 9 ))
164
+ texts .append (plt .text (x [i ] + 0.03 , y [i ] + 0.03 , label , fontsize = font_sizes [ "labels" ] ))
155
165
adjust_text (texts )
156
166
157
167
# stats and title
@@ -165,7 +175,7 @@ def _master_plot(
165
175
166
176
plt .title (
167
177
long_title ,
168
- fontsize = 12 ,
178
+ fontsize = font_sizes [ "title" ] ,
169
179
loc = "right" ,
170
180
horizontalalignment = "right" ,
171
181
family = "monospace" ,
0 commit comments