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

Upgrade Taylor Diagram function #874

Merged
merged 17 commits into from
Oct 12, 2022
Prev Previous commit
Next Next commit
add more flexibility for marker opened or closed
  • Loading branch information
lee1043 committed Oct 12, 2022
commit fb6591d67de9271c807ed69c9fe673287e4d55c6
52 changes: 32 additions & 20 deletions pcmdi_metrics/graphics/taylor_diagram/taylor_diagram.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import math


def TaylorDiagram(
stddev, corrcoef, refstd,
fig=None,
Expand All @@ -24,17 +25,17 @@ def TaylorDiagram(
debug=False):

"""Plot a Taylor diagram
Jiwoo Lee (PCMDI LLNL) - last update: September 2022

Jiwoo Lee (PCMDI LLNL) - last update: 2022. 10

This code was adpated from the ILAMB code that was written by Nathan Collier (ORNL)
(https://github.com/rubisco-sfa/ILAMB/blob/master/src/ILAMB/Post.py#L80)
and revised by Jiwoo Lee (LLNL) to add capabilities and enable more customizations
and revised by Jiwoo Lee (LLNL) to add capabilities and enable more customizations
for implementation into PCMDI Metrics Package (PMP).
The original code was written by Yannick Copin (https://gist.github.com/ycopin/3342888)

Reference for Taylor Diagram:
Taylor, K. E. (2001), Summarizing multiple aspects of model performance in a single diagram,
Taylor, K. E. (2001), Summarizing multiple aspects of model performance in a single diagram,
J. Geophys. Res., 106(D7), 7183–7192, http:https://dx.doi.org/10.1029/2000JD900719


Expand All @@ -49,7 +50,7 @@ def TaylorDiagram(
fig : matplotlib figure, optional
the matplotlib figure
rect : a 3-digit integer, optional
ax subplot rect, , default is 111, which indicate the figure has 1 row, 1 column, and this plot is the first plot.
ax subplot rect, , default is 111, which indicate the figure has 1 row, 1 column, and this plot is the first plot.
https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplot.html
https://matplotlib.org/stable/api/figure_api.html#matplotlib.figure.Figure.add_subplot
title : string, optional
Expand Down Expand Up @@ -92,6 +93,7 @@ def TaylorDiagram(
closed marker or opened marker
default - True
markercloses : list of bool, optional
if closed_marker is False but you want to have selected closed markers, provide list of True (close) or False (open)
default - None
debug : bool, optional
default - False
Expand Down Expand Up @@ -123,7 +125,7 @@ def TaylorDiagram(
if normalize:
stddev = stddev / refstd
refstd = 1.

# Radial axis range
smin = 0
if smax is None:
Expand All @@ -137,7 +139,7 @@ def TaylorDiagram(

if fig is None:
fig = plt.figure(figsize=(8, 8))

ax = fig.add_subplot(
rect, axes_class=FA.FloatingAxes, grid_helper=ghelper, title=title)

Expand Down Expand Up @@ -221,28 +223,38 @@ def TaylorDiagram(
markerclose = False

if markerclose:
marker_dict = dict(
color=colors[i],
mew=0
)
if closed_marker:
marker_dict = dict(
color=colors[i],
mew=0,
)
else:
marker_dict = dict(
mfc=colors[i],
mec='k',
mew=1
)
else:
marker_dict = dict(
mec=colors[i],
mfc='none',
mec=colors[i],
mfc='none',
mew=1,
)
# customize end

# -------------------------
# place marker on the graph
# -------------------------
ax.plot(
np.arccos(corrcoef[i]),
stddev[i],
marker,
ms=ms,
label=label,
np.arccos(corrcoef[i]),
stddev[i],
marker,
ms=ms,
label=label,
zorder=zorder,
**marker_dict)

# customize end
# debugging
if debug:
crmsd = math.sqrt(stddev[i]**2 + refstd**2 - 2 * stddev[i] * refstd * corrcoef[i]) # centered rms difference
print('i, label, corrcoef[i], np.arccos(corrcoef[i]), stddev[i], crmsd:', i, label, corrcoef[i], np.arccos(corrcoef[i]), stddev[i], crmsd)
Expand Down