Skip to content

Commit 75e3896

Browse files
authored
Merge pull request #568 from JuliaDataCubes/continue_cf_conventions
2 parents ed15b67 + b4c904c commit 75e3896

File tree

5 files changed

+206
-97
lines changed

5 files changed

+206
-97
lines changed

docs/src/.vitepress/config.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const navTemp = {
2727
{ text: 'Create', link: '/UserGuide/create' },
2828
{ text: 'Select', link: '/UserGuide/select' },
2929
{ text: 'Compute', link: '/UserGuide/compute' },
30+
{ text: 'Plot', link: '/UserGuide/plot' },
3031
{ text: 'Chunk', link: '/UserGuide/chunk' },
3132
{ text: 'Cache', link: '/UserGuide/cache' },
3233
{ text: 'Group', link: '/UserGuide/group' },
@@ -86,7 +87,7 @@ export default defineConfig({
8687
// cleanUrls: true,
8788
outDir: 'REPLACE_ME_DOCUMENTER_VITEPRESS', // This is required for MarkdownVitepress to work correctly...
8889
head: [
89-
['link', { rel: 'icon', href: '/favicon.ico' }],
90+
['link', { rel: 'icon', href: `${baseTemp.base}favicon.ico` }],
9091
['script', {src: `${getBaseRepository(baseTemp.base)}versions.js`}],
9192
['script', {src: `${baseTemp.base}siteinfo.js`}]
9293
],

docs/src/UserGuide/plot.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Plot YAXArrays
2+
3+
This section describes how to visualize YAXArrays.
4+
See also the [Plotting maps tutorial](../tutorials/plottingmaps.md) to plot geospatial data.
5+
All [plotting capabilities](https://rafaqz.github.io/DimensionalData.jl/stable/plots) of `AbstractDimArray` apply to a `YAXArrays` as well, because every `YAXArray` is also an `AbstractDimArray`.
6+
7+
## Plot a YAXArrray
8+
9+
Create a simple YAXArray:
10+
11+
```@example plot
12+
using CairoMakie
13+
using YAXArrays
14+
using DimensionalData
15+
16+
data = collect(reshape(1:20, 4, 5))
17+
axlist = (X(1:4), Y(1:5))
18+
a = YAXArray(axlist, data)
19+
```
20+
21+
Plot the entire array:
22+
23+
```@example plot
24+
plot(a)
25+
```
26+
27+
This will plot a heatmap, because the array is a matrix.
28+
29+
Plot the first column:
30+
31+
```@example plot
32+
plot(a[Y=1])
33+
```
34+
35+
This results in a scatter plot, because the subarray is a vector.
36+
37+
## Plot a YAXArrray with CF conventions
38+
39+
[Climate and Forecast Metadata Conventions](https://cfconventions.org/) are used to generate appropriate labels for the plot whenever possible.
40+
This requires the YAXArray to have metadata properties like `standard_name` and `units`.
41+
42+
Get a `Dataset` with CF meta data:
43+
44+
```@example plot
45+
using NetCDF
46+
using Downloads: download
47+
48+
path = download("https://archive.unidata.ucar.edu/software/netcdf/examples/tos_O1_2001-2002.nc", "example.nc")
49+
ds = open_dataset(path)
50+
```
51+
52+
Plot the first time step of the sea surface temperature with CF metadata:
53+
54+
```@example plot
55+
plot(ds.tos[time=1])
56+
```
57+
58+
Time in [Climate and Forecasting (CF) conventions](https://cfconventions.org/Data/cf-conventions/cf-conventions-1.12/cf-conventions.html#time-coordinate-units) requires conversion before plotting, e.g., to plot the sea surface temperature over time at a given location (e.g. the null island):
59+
60+
```@example plot
61+
a = ds.tos[lon = Near(0), lat = Near(0)]
62+
times = Ti(map(x -> DateTime(string(x)), a.time.val))
63+
a = YAXArray((times,), collect(a.data), a.properties)
64+
```
65+
66+
```@example plot
67+
plot(a)
68+
```
69+
70+
Or as as an explicit line plot:
71+
72+
```@example plot
73+
lines(a)
74+
```

docs/src/tutorials/plottingmaps.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ nothing # hide
134134
and now plot
135135

136136
````@example AoG
137-
data(dim_data) * mapping(:lon, :lat; color=:value) * visual(Scatter) |> draw
137+
data(dim_data) * mapping(:lon, :lat; color=Symbol("Near-Surface Air Temperature")) * visual(Scatter) |> draw
138138
````
139139

140140
::: warning
@@ -146,7 +146,7 @@ Note that we are using a `Scatter` type per point and not the `Heatmap` one. The
146146
set other attributes
147147

148148
````@example AoG
149-
plt = data(dim_data) * mapping(:lon, :lat; color=:value)
149+
plt = data(dim_data) * mapping(:lon, :lat; color=Symbol("Near-Surface Air Temperature"))
150150
draw(plt * visual(Scatter, marker=:rect), scales(Color = (; colormap = :plasma));
151151
axis = (width = 600, height = 400, limits=(0, 360, -90, 90)))
152152
````
@@ -166,14 +166,15 @@ nothing # hide
166166
````
167167

168168
````@example AoG
169-
plt = data(dim_time) * mapping(:lon, :lat; color = :value, layout = :time => nonnumeric)
169+
plt = data(dim_time) * mapping(:lon, :lat; color=Symbol("Near-Surface Air Temperature"), layout = :time => nonnumeric)
170170
draw(plt * visual(Scatter, marker=:rect))
171171
````
172172

173173
again, let's add some additional attributes
174174

175175
````@example AoG
176-
plt = data(dim_time) * mapping(:lon, :lat; color = :value, layout = :time => nonnumeric)
176+
plt = data(dim_time) * mapping(:lon, :lat; color=Symbol("Near-Surface Air Temperature"),
177+
layout = :time => nonnumeric)
177178
draw(plt * visual(Scatter, marker=:rect), scales(Color = (; colormap = :magma));
178179
axis = (; limits=(0, 360, -90, 90)),
179180
figure=(; size=(900,600)))
@@ -182,14 +183,16 @@ draw(plt * visual(Scatter, marker=:rect), scales(Color = (; colormap = :magma));
182183
most [Makie plot functions](https://docs.makie.org/stable/reference/plots/overview) should work. See `lines` for example
183184

184185
````@example AoG
185-
plt = data(dim_data[lon=50..100]) * mapping(:lat, :value => "tas"; color=:value => "tas")
186+
plt = data(dim_data[lon=50..100]) * mapping(:lat, Symbol("Near-Surface Air Temperature") => "tas";
187+
color=Symbol("Near-Surface Air Temperature") => "tas")
186188
draw(plt * visual(Lines); figure=(; size=(650,400)))
187189
````
188190

189191
or faceting them
190192

191193
````@example AoG
192-
plt = data(dim_data[lon=50..59]) * mapping(:lat, :value => "tas"; color=:value => "tas",
194+
plt = data(dim_data[lon=50..59]) * mapping(:lat, Symbol("Near-Surface Air Temperature") => "tas";
195+
color=Symbol("Near-Surface Air Temperature") => "tas",
193196
layout = :lon => nonnumeric)
194197
draw(plt * visual(Lines); figure=(; size=(650,400)))
195198
````
@@ -204,7 +207,7 @@ dim_series = c[time=DateTime("2015-01-01") .. DateTime("2015-01-04"), lon = 150
204207
and plot
205208

206209
````@example AoG
207-
plt = data(dim_series) * mapping(:time, :value => "tas"; color=:lon => nonnumeric)
210+
plt = data(dim_series) * mapping(:time, Symbol("Near-Surface Air Temperature") => "tas"; color=:lon => nonnumeric)
208211
draw(plt * visual(ScatterLines), scales(Color = (; palette = :tableau_colorblind));
209212
figure=(; size=(800,400)))
210213
````
@@ -214,7 +217,7 @@ draw(plt * visual(ScatterLines), scales(Color = (; palette = :tableau_colorblind
214217
Basic statistical [analysis](https://aog.makie.org/stable/generated/analyses/) can also be done, for example:
215218

216219
````@example AoG
217-
specs = data(dim_data[lat=50..55]) * mapping(:lon, :value => "tas"; color=:lat => nonnumeric)
220+
specs = data(dim_data[lat=50..55]) * mapping(:lon, Symbol("Near-Surface Air Temperature") => "tas"; color=:lat => nonnumeric)
218221
specs *= (smooth() + visual(Scatter))
219222
draw(specs; figure=(; size=(700,400)))
220223
````

0 commit comments

Comments
 (0)