Skip to content

Commit 08a9cf8

Browse files
committed
Resize font automatically
We add a functionality which resizes the fonts automatically when the figure size is changed.
1 parent f15a7a2 commit 08a9cf8

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

eda/configure.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
transform_input = {
99
"use_cols": lambda x: list(map(int, x.split())),
10-
"figure_size": lambda x: list(map(int, x.split())),
10+
"figure_size": lambda x: list(map(float, x.split())),
1111
"xcolumn": lambda x: x,
1212
"ycolumn": lambda x: x,
1313
"xlabel": lambda x: x,
1414
"ylabel": lambda x: x,
15-
"xlimit": lambda x: list(map(int, x.split())),
16-
"ylimit": lambda x: list(map(int, x.split())),
15+
"xlimit": lambda x: list(map(float, x.split())),
16+
"ylimit": lambda x: list(map(float, x.split())),
1717
"skip_header": lambda x: int(x),
1818
"legend_location": lambda x: x,
1919
"title": lambda x: x,

eda/kinetics.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
)
3333

3434
# plotting parameters
35+
DEFAULT_FIG_HEIGHT = 5
3536
EXP_COLOR = "black"
3637
MARKERS = ["o", "v", "^", "s", "D", "*", "P", "X", "<", ">"]
3738
FIT_COLOR = "grey"
@@ -83,15 +84,21 @@ def plot_kinetics(
8384
ax.set_xlim(*x_lim)
8485
if y_lim:
8586
ax.set_ylim(*y_lim)
86-
ax.set_xlabel(x_lab, fontsize=16)
87-
ax.set_ylabel(y_lab, fontsize=16)
87+
font_ratio = fig_size[1] / DEFAULT_FIG_HEIGHT + 0.3
88+
ax.set_xlabel(x_lab, fontsize=16 * font_ratio)
89+
ax.set_ylabel(y_lab, fontsize=16 * font_ratio)
8890
for side in ["top", "right"]:
8991
ax.spines[side].set_visible(False)
9092
ax.set_title(title, fontsize=18)
9193
# remove duplicated legend
9294
handles, labels = plt.gca().get_legend_handles_labels()
9395
by_label = OrderedDict(zip(labels, handles))
94-
plt.legend(by_label.values(), by_label.keys(), loc=legend_loc)
96+
plt.legend(
97+
by_label.values(),
98+
by_label.keys(),
99+
loc=legend_loc,
100+
fontsize=10 * font_ratio)
101+
plt.tight_layout()
95102
plt.show()
96103

97104

eda/spectrum.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
)
2525

2626
# plotting parameters
27+
DEFAULT_FIG_HEIGHT = 5
2728
COLORS = ["black", "C0", "C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8", "C9"]
2829

2930

@@ -61,12 +62,14 @@ def plot_spectrum(
6162
ax.set_xlim(*x_lim)
6263
if y_lim:
6364
ax.set_ylim(*y_lim)
64-
ax.set_xlabel(x_lab, fontsize=16)
65-
ax.set_ylabel(y_lab, fontsize=16)
65+
font_ratio = fig_size[1] / DEFAULT_FIG_HEIGHT + 0.3
66+
ax.set_xlabel(x_lab, fontsize=16 * font_ratio)
67+
ax.set_ylabel(y_lab, fontsize=16 * font_ratio)
6668
for side in ["top", "right"]:
6769
ax.spines[side].set_visible(False)
68-
ax.set_title(title, fontsize=18)
69-
plt.legend(loc=legend_loc)
70+
ax.set_title(title, fontsize=18 * font_ratio)
71+
plt.legend(loc=legend_loc, fontsize=10 * font_ratio)
72+
plt.tight_layout()
7073
plt.show()
7174

7275

0 commit comments

Comments
 (0)