Skip to content

Commit

Permalink
Merge pull request #457 from NCAR/taylor_2
Browse files Browse the repository at this point in the history
Creating taylor_2 example
  • Loading branch information
anissa111 committed Jul 15, 2022
2 parents 4a9878e + b8bf924 commit 9584b60
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
78 changes: 78 additions & 0 deletions Gallery/TaylorDiagrams/NCL_taylor_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"""
NCL_taylor_2.py
===============
Concepts illustrated:
- Creating a simple Taylor Diagram
- Adding background options for the diagram
See following URLs to see the reproduced NCL plot & script:
- Original NCL script: https://www.ncl.ucar.edu/Applications/Scripts/taylor_2.ncl
- Original NCL plot: https://www.ncl.ucar.edu/Applications/Images/taylor_2_lg.png
Note: Due to to limitations of matplotlib's axisartist toolkit, we cannot include minor tick marks
between 0.9 and 0.99, as seen in the original NCL plot.
"""

###############################################################################
# Import packages:

import matplotlib.pyplot as plt
import numpy as np

import geocat.viz as gv

###############################################################################
# Create dummy data:

# p dataset
pstddev = [0.6, 0.5, 0.45, 0.75, 1.15] # standard deviation
pcorrcoef = [0.24, 0.75, 1, 0.93, 0.37] # correlation coefficient

# t dataset
tstddev = [0.75, 0.64, 0.4, 0.85, 1.15]
tcorrcoef = [0.24, 0.75, 0.47, 0.88, 0.73]

###############################################################################
# Plot

# Create figure and Taylor Diagram instance
fig = plt.figure(figsize=(12, 12))
dia = gv.TaylorDiagram(fig=fig, label='REF')
ax = plt.gca()

# Add model sets for p and t datasets
dia.add_model_set(
pstddev,
pcorrcoef,
fontsize=20,
xytext=(-5, 10), # marker label location, in pixels
color='red',
marker='o',
facecolors='none',
s=100) # marker size
dia.add_model_set(
tstddev,
tcorrcoef,
fontsize=20,
xytext=(-5, 10), # marker label location, in pixels
color='blue',
marker='D',
facecolors='none',
s=100)

# Add RMS contours, and label them
dia.add_contours(levels=np.arange(0, 1.1, 0.25),
colors='lightgrey',
linewidths=0.5)

# Add y axis grid
dia.add_ygrid(np.array([0.5, 1.5]), color='grey')

# Add x axis grid
dia.add_xgrid(np.array([0.6, 0.9]))

# Add figure title
plt.title("Example", size=26, pad=45)

# Show the plot
plt.show()
6 changes: 6 additions & 0 deletions Gallery/TaylorDiagrams/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _taylor_diagrams_examples:

.. _taylor-diagrams-index:

Taylor Diagrams
===============

0 comments on commit 9584b60

Please sign in to comment.