Plotting
modelskill.plotting
The plotting module provides functions useful for skill assessment that can be used independently of the comparison module.
scatter
is a function that can be used to plot a scatter suitable for skill assessment, with a 1:1 line and a linear regression line.wind_rose
is a function that can be used to plot a dual wind rose to compare two datasets of magnitudes and directions.spatial_overview
is a function that can be used to plot a spatial overview of two datasets.temporal_coverage
is a function that can be used to plot the temporal coverage of two datasets.
scatter
scatter(x, y, *, bins=120, quantiles=None, fit_to_quantiles=False, show_points=None, show_hist=None, show_density=None, norm=None, backend='matplotlib', figsize=(8, 8), xlim=None, ylim=None, reg_method='ols', title='', xlabel='', ylabel='', skill_table=False, skill_scores=None, skill_score_unit='', ax=None, **kwargs)
Scatter plot showing compared data: observation vs modelled Optionally, with density histogram.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
ndarray
|
X values e.g model values, must be same length as y |
required |
y |
ndarray
|
Y values e.g observation values, must be same length as x |
required |
bins |
int | float
|
bins for the 2D histogram on the background. By default 120 bins. if int, represents the number of bins of 2D if float, represents the bin size if sequence (list of int or float), represents the bin edges |
120
|
quantiles |
int | Sequence[float] | None
|
number of quantiles for QQ-plot, by default None and will depend on the scatter data length (10, 100 or 1000) if int, this is the number of points if sequence (list of floats), represents the desired quantiles (from 0 to 1) |
None
|
fit_to_quantiles |
bool
|
by default the regression line is fitted to all data, if True, it is fitted to the quantiles which can be useful to represent the extremes of the distribution, by default False |
False
|
show_points |
(bool, int, float)
|
Should the scatter points be displayed? None means: show all points if fewer than 1e4, otherwise show 1e4 sample points, by default None. float: fraction of points to show on plot from 0 to 1. eg 0.5 shows 50% of the points. int: if 'n' (int) given, then 'n' points will be displayed, randomly selected. |
None
|
show_hist |
bool
|
show the data density as a 2d histogram, by default None |
None
|
show_density |
Optional[bool]
|
show the data density as a colormap of the scatter, by default None. If both |
None
|
norm |
Normalize
|
colormap normalization If None, defaults to matplotlib.colors.PowerNorm(vmin=1,gamma=0.5) |
None
|
backend |
str
|
use "plotly" (interactive) or "matplotlib" backend, by default "matplotlib" |
'matplotlib'
|
figsize |
tuple
|
width and height of the figure, by default (8, 8) |
(8, 8)
|
xlim |
tuple
|
plot range for the observation (xmin, xmax), by default None |
None
|
ylim |
tuple
|
plot range for the model (ymin, ymax), by default None |
None
|
reg_method |
str or bool
|
method for determining the regression line "ols" : ordinary least squares regression "odr" : orthogonal distance regression, False : no regression line by default "ols" |
'ols'
|
title |
str
|
plot title, by default None |
''
|
xlabel |
str
|
x-label text on plot, by default None |
''
|
ylabel |
str
|
y-label text on plot, by default None |
''
|
skill_table |
Optional[str | Sequence[str] | bool]
|
calculate skill scores and show in box next to the plot, True will show default metrics, list of metrics will show these skill scores, by default False, Note: cannot be used together with skill_scores argument |
False
|
skill_scores |
dict[str, float]
|
dictionary with skill scores to be shown in box next to the plot, by default None Note: cannot be used together with skill_table argument |
None
|
skill_score_unit |
str
|
unit for skill_scores, by default None |
''
|
ax |
Axes
|
axes to plot on, by default None |
None
|
**kwargs |
|
{}
|
Returns:
Type | Description |
---|---|
Axes
|
The axes on which the scatter plot was drawn. |
Source code in modelskill/plotting/_scatter.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
|
spatial_overview
Plot observation points on a map showing the model domain
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obs |
List[Observation]
|
List of observations to be shown on map |
required |
mod |
Union[ModelResult, GeometryFM]
|
Model domain to be shown as outline |
None
|
ax |
Adding to existing axis, instead of creating new fig |
None
|
|
figsize |
(float, float)
|
figure size, by default None |
None
|
title |
Optional[str]
|
plot title, default empty |
None
|
See Also
temporal_coverage
Returns:
Type | Description |
---|---|
Axes
|
The matplotlib axes object |
Examples:
>>> import modelskill as ms
>>> o1 = ms.PointObservation('HKNA_Hm0.dfs0', item=0, x=4.2420, y=52.6887, name="HKNA")
>>> o2 = ms.TrackObservation("Alti_c2_Dutch.dfs0", item=3, name="c2")
>>> mr1 = ms.DfsuModelResult('HKZN_local_2017_DutchCoast.dfsu', name='SW_1', item=0)
>>> mr2 = ms.DfsuModelResult('HKZN_local_2017_DutchCoast_v2.dfsu', name='SW_2', item=0)
>>> ms.plotting.spatial_overview([o1, o2], [mr1, mr2])
Source code in modelskill/plotting/_spatial_overview.py
taylor_diagram
taylor_diagram(obs_std, points, figsize=(7, 7), obs_text='Observations', normalize_std=False, ax=None, title='Taylor diagram')
Plot a Taylor diagram using the given observations and points.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obs_std |
float
|
Standard deviation of the observations. |
required |
points |
list of TaylorPoint objects or a single TaylorPoint object
|
Points to plot on the Taylor diagram. |
required |
figsize |
tuple
|
Figure size in inches. Default is (7, 7). |
(7, 7)
|
obs_text |
str
|
Label for the observations. Default is "Observations". |
'Observations'
|
normalize_std |
bool
|
Whether to normalize the standard deviation of the points by the standard deviation of the observations. Default is False. |
False
|
title |
str
|
Title of the plot. Default is "Taylor diagram". |
'Taylor diagram'
|
Returns:
Type | Description |
---|---|
Figure
|
The matplotlib figure object |
Source code in modelskill/plotting/_taylor_diagram.py
temporal_coverage
temporal_coverage(obs=None, mod=None, *, limit_to_model_period=True, marker='_', ax=None, figsize=None, title=None)
Plot graph showing temporal coverage for all observations and models
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obs |
List[Observation]
|
Show observation(s) as separate lines on plot |
None
|
mod |
List[ModelResult]
|
Show model(s) as separate lines on plot, by default None |
None
|
limit_to_model_period |
bool
|
Show temporal coverage only for period covered by the model, by default True |
True
|
marker |
str
|
plot marker for observations, by default "_" |
'_'
|
ax |
Adding to existing axis, instead of creating new fig |
None
|
|
figsize |
Tuple(float, float)
|
size of figure, by default (7, 0.45*n_lines) |
None
|
title |
plot title, default empty |
None
|
See Also
spatial_overview
Returns:
Type | Description |
---|---|
Axes
|
The matplotlib axes object |
Examples:
>>> import modelskill as ms
>>> o1 = ms.PointObservation('HKNA_Hm0.dfs0', item=0, x=4.2420, y=52.6887, name="HKNA")
>>> o2 = ms.TrackObservation("Alti_c2_Dutch.dfs0", item=3, name="c2")
>>> mr1 = ms.DfsuModelResult('HKZN_local_2017_DutchCoast.dfsu', name='SW_1', item=0)
>>> mr2 = ms.DfsuModelResult('HKZN_local_2017_DutchCoast_v2.dfsu', name='SW_2', item=0)
>>> ms.plotting.temporal_coverage([o1, o2], [mr1, mr2])
>>> ms.plotting.temporal_coverage([o1, o2], mr2, limit_to_model_period=False)
>>> ms.plotting.temporal_coverage(o2, [mr1, mr2], marker=".")
>>> ms.plotting.temporal_coverage(mod=[mr1, mr2], figsize=(5,3))
Source code in modelskill/plotting/_temporal_coverage.py
wind_rose
wind_rose(data, *, labels=('Measurement', 'Model'), mag_step=None, n_sectors=16, calm_threshold=None, calm_size=None, calm_text='Calm', r_step=0.1, r_max=None, legend=True, cmap1='viridis', cmap2='Greys', mag_bins=None, max_bin=None, n_dir_labels=None, secondary_dir_step_factor=2.0, figsize=(8, 8), ax=None, title=None)
Plots a (dual) wind (wave or current) roses with calms.
The size of the calm is determined by the primary (measurement) data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
array with 2 or 4 columns (magnitude, direction, magnitude2, direction2) |
required | |
labels |
labels for the legend(s) |
('Measurement', 'Model')
|
|
mag_step |
Optional[float]
|
discretization for magnitude (delta_r, in radial direction ) |
None
|
n_sectors |
int
|
number of directional sectors |
16
|
calm_threshold |
Optional[float]
|
minimum value for data being counted as valid (i.e. below this is calm) |
None
|
calm_text |
str
|
text to display in calm. |
'Calm'
|
r_step |
float
|
radial axis discretization. By default 0.1 i.e. every 10%. |
0.1
|
r_max |
Optional[float]
|
maximum radius (%) of plot, e.g. if 50% wanted then r_max=0.5 |
None
|
max_bin |
Optional[float]
|
max value to truncate the data, e.g., max_bin=1.0 if hm0=1m is the desired final bin. |
None
|
mag_bins |
array of floats (optional) Default = None
|
force bins to array of values, e.g. when specifying non-equidistant bins. |
None
|
legend |
bool
|
show legend |
True
|
cmap1 |
string. Default= 'viridis'
|
colormap for main axis |
'viridis'
|
cmap2 |
string. Default= 'Greys'
|
colormap for secondary axis |
'Greys'
|
n_dir_labels |
int. Default= 4
|
number of labels in the polar plot, choose between 4, 8 or 16, default is to use the same as n_sectors |
None
|
secondary_dir_step_factor |
float. Default= 2.0
|
reduce width of secondary axis by this factor |
2.0
|
figsize |
Tuple[float, float]
|
figure size |
(8, 8)
|
ax |
Matplotlib axis to plot on defined as polar, it can be done using "subplot_kw = dict(projection = 'polar')". Default = None, new axis created. |
None
|
|
title |
title of the plot |
None
|
Returns:
Type | Description |
---|---|
Axes
|
Matplotlib axis with the plot |
Source code in modelskill/plotting/_wind_rose.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
|