Skip to content

Commit 62182d7

Browse files
authored
add font size and xy_lim changes (#68)
1 parent 15f20a6 commit 62182d7

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

cinnabar/plotting.py

+18-8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ def _master_plot(
3030
dpi: float = "figure",
3131
data_labels: list = [],
3232
axis_padding: float = 0.5,
33+
xy_lim: list = [],
34+
font_sizes: dict = {"title": 12, "labels": 9, "other": 12},
3335
):
3436
"""Handles the aesthetics of the plots in one place.
3537
@@ -81,26 +83,34 @@ def _master_plot(
8183
list of labels for each data point
8284
axis_padding : float, default = 0.5
8385
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")
8490
8591
Returns
8692
-------
8793
8894
"""
8995
nsamples = len(x)
9096
# 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"]
94100

95101
fig = plt.figure(figsize=(figsize, figsize))
96102
plt.subplots_adjust(left=0.2, right=0.8, bottom=0.2, top=0.8)
97103

98104
plt.xlabel(f"{xlabel} {quantity} ({units})")
99105
plt.ylabel(f"{ylabel} {quantity} ({units})")
100106

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]
104114

105115
plt.xlim(scale)
106116
plt.ylim(scale)
@@ -151,7 +161,7 @@ def _master_plot(
151161
# Label points
152162
texts = []
153163
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"]))
155165
adjust_text(texts)
156166

157167
# stats and title
@@ -165,7 +175,7 @@ def _master_plot(
165175

166176
plt.title(
167177
long_title,
168-
fontsize=12,
178+
fontsize=font_sizes["title"],
169179
loc="right",
170180
horizontalalignment="right",
171181
family="monospace",

0 commit comments

Comments
 (0)