Skip to content

Commit

Permalink
update example notebook, add annotate_textcolors_threshold parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
lee1043 committed Nov 8, 2023
1 parent 3b4959d commit dca315b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 58 deletions.
100 changes: 44 additions & 56 deletions pcmdi_metrics/graphics/portrait_plot/portrait_plot_example.ipynb

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions pcmdi_metrics/graphics/portrait_plot/portrait_plot_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def portrait_plot(
annotate=False,
annotate_data=None,
annotate_textcolors=("black", "white"),
annotate_textcolors_threshold=(-2, 2),
annotate_fontsize=15,
annotate_format="{x:.2f}",
figsize=(12, 10),
Expand Down Expand Up @@ -63,6 +64,7 @@ def portrait_plot(
but work only for heatmap style map (i.e., no triangles)
- `annotate_data`: 2d numpy array, default=None. If None, the image's data is used. Optional.
- `annotate_textcolors`: Tuple. A pair of colors for annotation text. Default is ("black", "white")
- `annotate_textcolors_threshold`: Tuple or float. Value in data units according to which the colors from textcolors are applied. Default=(-2, 2)
- `annotate_fontsize`: number (int/float), default=15. Font size for annotation
- `annotate_format`: format for annotate value, default="{x:.2f}"
- `figsize`: tuple of two numbers (width, height), default=(12, 10), figure size in inches
Expand Down Expand Up @@ -171,14 +173,14 @@ def portrait_plot(
sys.exit("Error: annotate_data has different size than data")
else:
annotate_data = data
annotate_heatmap(
ax = annotate_heatmap(
im,
ax=ax,
data=data,
annotate_data=annotate_data,
valfmt=annotate_format,
textcolors=annotate_textcolors,
threshold=(2, -2),
threshold=annotate_textcolors_threshold,
fontsize=annotate_fontsize,
)

Expand Down Expand Up @@ -503,6 +505,8 @@ def annotate_heatmap(
kw.update(color=textcolors[int(data[i, j] > threshold)])
text = ax.text(j + 0.5, i + 0.5, valfmt(annotate_data[i, j], None), **kw)
texts.append(text)

return ax


# ======================================================================
Expand Down

0 comments on commit dca315b

Please sign in to comment.