Skip to content

Commit 985fcee

Browse files
authored
Merge branch 'main' into 405_sic_ljw
2 parents dae3443 + 26326e5 commit 985fcee

File tree

2 files changed

+53
-58
lines changed

2 files changed

+53
-58
lines changed

pcmdi_metrics/graphics/portrait_plot/portrait_plot_example.ipynb

Lines changed: 44 additions & 56 deletions
Large diffs are not rendered by default.

pcmdi_metrics/graphics/portrait_plot/portrait_plot_lib.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ def portrait_plot(
1616
ax=None,
1717
annotate=False,
1818
annotate_data=None,
19+
annotate_textcolors=("black", "white"),
20+
annotate_textcolors_threshold=(-2, 2),
1921
annotate_fontsize=15,
2022
annotate_format="{x:.2f}",
2123
figsize=(12, 10),
@@ -61,6 +63,8 @@ def portrait_plot(
6163
- `annotate`: bool, default=False, add annotating text if true,
6264
but work only for heatmap style map (i.e., no triangles)
6365
- `annotate_data`: 2d numpy array, default=None. If None, the image's data is used. Optional.
66+
- `annotate_textcolors`: Tuple. A pair of colors for annotation text. Default is ("black", "white")
67+
- `annotate_textcolors_threshold`: Tuple or float. Value in data units according to which the colors from textcolors are applied. Default=(-2, 2)
6468
- `annotate_fontsize`: number (int/float), default=15. Font size for annotation
6569
- `annotate_format`: format for annotate value, default="{x:.2f}"
6670
- `figsize`: tuple of two numbers (width, height), default=(12, 10), figure size in inches
@@ -169,13 +173,14 @@ def portrait_plot(
169173
sys.exit("Error: annotate_data has different size than data")
170174
else:
171175
annotate_data = data
172-
annotate_heatmap(
176+
ax = annotate_heatmap(
173177
im,
174178
ax=ax,
175179
data=data,
176180
annotate_data=annotate_data,
177181
valfmt=annotate_format,
178-
threshold=(2, -2),
182+
textcolors=annotate_textcolors,
183+
threshold=annotate_textcolors_threshold,
179184
fontsize=annotate_fontsize,
180185
)
181186

@@ -501,6 +506,8 @@ def annotate_heatmap(
501506
text = ax.text(j + 0.5, i + 0.5, valfmt(annotate_data[i, j], None), **kw)
502507
texts.append(text)
503508

509+
return ax
510+
504511

505512
# ======================================================================
506513
# Portrait plot 2 (two triangles)

0 commit comments

Comments
 (0)