|
3 | 3 | import numpy as np |
4 | 4 | import matplotlib.pyplot as plt |
5 | 5 | import matplotlib |
| 6 | +from matplotlib.font_manager import FontProperties |
6 | 7 | from matplotlib.ticker import MaxNLocator, ScalarFormatter, LogLocator |
7 | 8 | from matplotlib.textpath import TextPath |
8 | 9 | from numpy import meshgrid |
@@ -315,31 +316,33 @@ def _add_watermark(self, fig, axes, figsize, text, dpi=300, size_scale=1.0): # |
315 | 316 | dx, dy = figsize |
316 | 317 | dy, dx = dy * dpi, dx * dpi |
317 | 318 | rotation = 180 / np.pi * np.arctan2(-dy, dx) |
318 | | - fontdict = self.parent.config["watermark_text_kwargs"] |
319 | | - if "usetex" in fontdict: |
320 | | - usetex = fontdict["usetex"] |
321 | | - else: |
322 | | - usetex = self.parent.config["usetex"] |
323 | | - fontdict["usetex"] = usetex |
324 | | - if fontdict["usetex"]: |
| 319 | + property_dict = self.parent.config["watermark_text_kwargs"] |
| 320 | + |
| 321 | + keys_in_font_dict = ["family", "style", "variant", "weight", "stretch", "size"] |
| 322 | + fontdict = {k: property_dict[k] for k in keys_in_font_dict if k in property_dict} |
| 323 | + font_prop = FontProperties(**fontdict) |
| 324 | + usetex = property_dict.get("usetex", self.parent.config["usetex"]) |
| 325 | + if usetex: |
325 | 326 | px, py, scale = 0.5, 0.5, 1.0 |
326 | 327 | else: |
327 | | - px, py, scale = 0.45, 0.55, 0.8 |
328 | | - bb0 = TextPath((0, 0), text, size=50, prop=fontdict, usetex=usetex).get_extents() |
329 | | - bb1 = TextPath((0, 0), text, size=51, prop=fontdict, usetex=usetex).get_extents() |
| 328 | + px, py, scale = 0.5, 0.5, 0.8 |
| 329 | + |
| 330 | + bb0 = TextPath((0, 0), text, size=50, prop=font_prop, usetex=usetex).get_extents() |
| 331 | + bb1 = TextPath((0, 0), text, size=51, prop=font_prop, usetex=usetex).get_extents() |
330 | 332 | dw = (bb1.width - bb0.width) * (dpi / 100) |
331 | 333 | dh = (bb1.height - bb0.height) * (dpi / 100) |
332 | 334 | size = np.sqrt(dy ** 2 + dx ** 2) / (dh * abs(dy / dx) + dw) * 0.6 * scale * size_scale |
333 | 335 | if axes is not None: |
334 | | - if fontdict["usetex"]: |
| 336 | + if usetex: |
335 | 337 | size *= 0.7 |
336 | 338 | else: |
337 | | - size *= 0.85 |
338 | | - fontdict["size"] = int(size) |
| 339 | + size *= 0.8 |
| 340 | + size = int(size) |
| 341 | + print(f"Font size is {size}") |
339 | 342 | if axes is None: |
340 | | - fig.text(px, py, text, fontdict=fontdict, rotation=rotation) |
| 343 | + fig.text(px, py, text, fontdict=property_dict, rotation=rotation, fontsize=size) |
341 | 344 | else: |
342 | | - axes.text(px, py, text, transform=axes.transAxes, fontdict=fontdict, rotation=rotation) |
| 345 | + axes.text(px, py, text, transform=axes.transAxes, fontdict=property_dict, rotation=rotation, fontsize=size) |
343 | 346 |
|
344 | 347 | def plot_walks( |
345 | 348 | self, |
@@ -1215,11 +1218,10 @@ def _plot_bars(self, ax, parameter, chain, flip=False, summary=False): # pragma |
1215 | 1218 | kde = chain.config["kde"] |
1216 | 1219 | zorder = chain.config["zorder"] |
1217 | 1220 | title_size = self.parent.config["label_font_size"] |
1218 | | - |
1219 | 1221 | chain_row = chain.get_data(parameter) |
1220 | 1222 | weights = chain.weights |
1221 | 1223 | if smooth or kde: |
1222 | | - xs, ys, _ = self.parent.analysis._get_smoothed_histogram(chain, parameter) |
| 1224 | + xs, ys, _ = self.parent.analysis._get_smoothed_histogram(chain, parameter, pad=True) |
1223 | 1225 | if flip: |
1224 | 1226 | ax.plot(ys, xs, color=colour, ls=linestyle, lw=linewidth, zorder=zorder) |
1225 | 1227 | else: |
|
0 commit comments