Skip to content

Commit

Permalink
Merge pull request #186 from jukent/taylordiagram
Browse files Browse the repository at this point in the history
add taylordiagram example
  • Loading branch information
jukent authored Jan 23, 2024
2 parents e9b37d9 + 808203d commit f23bb91
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 0 deletions.
Binary file added docs/_static/thumbnails/taylor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ Here are some examples of how to use geocat-viz.
examples/find_local_extrema.ipynb
examples/plot_contour_labels.ipynb
examples/plot_extrema_labels.ipynb
examples/taylor.ipynb
116 changes: 116 additions & 0 deletions docs/examples/taylor.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# `TaylorDiagram`\n",
"\n",
"This notebook is a simple example of the GeoCAT-viz class <a href=\"../user_api/generated/geocat.viz.TaylorDiagram.html\">`TaylorDiagram`</a> class."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# Import packages:\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"import geocat.viz as gv"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Create sample data:\n",
"\n",
"# Model A\n",
"a_sdev = [1.230, 0.988, 1.092, 1.172, 1.064, 0.966, 1.079] # normalized standard deviation\n",
"a_ccorr = [0.958, 0.973, 0.740, 0.743, 0.922, 0.982, 0.952] # correlation coefficient\n",
"a_bias = [2.7, -1.5, 17.31, -20.11, 12.5, 8.341, -4.7] # bias (%)\n",
"\n",
"# Model B\n",
"b_sdev = [1.129, 0.996, 1.016, 1.134, 1.023, 0.962, 1.048] # normalized standard deviation\n",
"b_ccorr = [0.963, 0.975, 0.801, 0.814, 0.946, 0.984, 0.968] # correlation coefficient\n",
"b_bias = [1.7, 2.5, -17.31, 20.11, 19.5, 7.341, 9.2]\n",
"\n",
"# Sample Variable List\n",
"var_list = ['Surface Pressure', '2m Temp', 'Dew Point Temp', 'U Wind', 'V Wind', 'Precip', 'Cloud Cov']"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Create figure and TaylorDiagram instance\n",
"fig = plt.figure(figsize=(10, 10))\n",
"taylor = gv.TaylorDiagram(fig=fig, label='REF')\n",
"\n",
"# Draw diagonal dashed lines from origin to correlation values\n",
"# Also enforces proper X-Y ratio\n",
"taylor.add_xgrid(np.array([0.6, 0.9]))\n",
"\n",
"# Add models to Taylor diagram\n",
"taylor.add_model_set(a_sdev,\n",
" a_ccorr,\n",
" percent_bias_on=True, # indicate marker and size to be plotted based on bias_array\n",
" bias_array=a_bias, # specify bias array\n",
" color='red',\n",
" label='Model A',\n",
" fontsize=16)\n",
"\n",
"taylor.add_model_set(b_sdev,\n",
" b_ccorr,\n",
" percent_bias_on=True,\n",
" bias_array=b_bias,\n",
" color='blue',\n",
" label='Model B',\n",
" fontsize=16)\n",
"\n",
"# Add model name\n",
"taylor.add_model_name(var_list, fontsize=16)\n",
"\n",
"# Add figure legend\n",
"taylor.add_legend(fontsize=16)\n",
"\n",
"# Add bias legend\n",
"taylor.add_bias_legend()\n",
"\n",
"# Add constant centered RMS difference contours.\n",
"taylor.add_contours(levels=np.arange(0, 1.1, 0.25),\n",
" colors='lightgrey',\n",
" linewidths=0.5);"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "geocat_sandbox",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.10"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
4 changes: 4 additions & 0 deletions docs/gallery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@
- title: 'set_axes_limits_and_ticks'
path: examples/set_axes_limits_and_ticks.ipynb
thumbnail: _static/thumbnails/set_axes_limits_and_ticks.png

- title: 'TaylorDiagram'
path: examples/taylor.ipynb
thumbnail: _static/thumbnails/taylor.png

0 comments on commit f23bb91

Please sign in to comment.