Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Portrait plot annotate text color #999

Merged
merged 3 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
100 changes: 44 additions & 56 deletions pcmdi_metrics/graphics/portrait_plot/portrait_plot_example.ipynb

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions pcmdi_metrics/graphics/portrait_plot/portrait_plot_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def portrait_plot(
ax=None,
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 @@ -61,6 +63,8 @@ def portrait_plot(
- `annotate`: bool, default=False, add annotating text if true,
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 @@ -169,13 +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,
threshold=(2, -2),
textcolors=annotate_textcolors,
threshold=annotate_textcolors_threshold,
fontsize=annotate_fontsize,
)

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

return ax


# ======================================================================
# Portrait plot 2 (two triangles)
Expand Down