# How to make a wind rose in Julia

**URL:** <https://discourse.julialang.org/t/how-to-make-a-wind-rose-in-julia/40229>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [May 27, 2020, 1:10am UTC](https://discourse.julialang.org/t/how-to-make-a-wind-rose-in-julia/40229 "2020-05-27T01:10:43Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![scone](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@scone](https://discourse.julialang.org/u/scone)\
**Post date:** [May 27, 2020, 1:10am UTC](https://discourse.julialang.org/t/how-to-make-a-wind-rose-in-julia/40229/1 "2020-05-27T01:10:43Z")

</div>

Hi,

I am trying to just make a wind rose. Its a pretty basic thing, and I can’t find any implementation of it in Julia. The closest I have come is to use the plotlyjs backend, but I can’t figure out how to reverse and rotate the axis and it doesn’t seem to display properly in Juno:

```julia
using Plots
plotlyjs()
theta = range(0, stop = 1.5π, length = 100)
r = abs.(0.1 * randn(100) + sin.(3Θ))
bar(theta, r, proj = :polar, m = 0)
plot(theta,r)
title!("rose")

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/6/4/6433c81eac53c4d5d0c446fb7d8acae9e3d05572.png)

I am not picky about how it looks, I just need the basics. If anyone has any ideas or has seen a working implementation of this, please let me know…

Thanks

---

<div class="post-metadata">

**Author:** ![jmkuhn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmkuhn/32/2090_2.png) [@jmkuhn](https://discourse.julialang.org/u/jmkuhn)\
**Post date:** [May 27, 2020, 3:11am UTC](https://discourse.julialang.org/t/how-to-make-a-wind-rose-in-julia/40229/3 "2020-05-27T03:11:21Z")

</div>

[https://www.generic-mapping-tools.org/GMT.jl/latest/#GMT.rose](https://www.generic-mapping-tools.org/GMT.jl/latest/#GMT.rose)

@joa-quim

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [May 27, 2020, 4:20pm UTC](https://discourse.julialang.org/t/how-to-make-a-wind-rose-in-julia/40229/4 "2020-05-27T16:20:51Z")

</div>

Sorry, a bit busy right now but ping me if you need help using the GMT.jl wrapper to reproduce the plenty of examples in our [test suit](https://github.com/GenericMappingTools/gmt/tree/master/test/psrose). Note that the examples are in postscript (that’s our testing mechanism works)

---

<div class="post-metadata">

**Author:** ![scone](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@scone](https://discourse.julialang.org/u/scone)\
**Post date:** [May 27, 2020, 7:24pm UTC](https://discourse.julialang.org/t/how-to-make-a-wind-rose-in-julia/40229/5 "2020-05-27T19:24:10Z")

</div>

Thanks for your responses! GMT looks like an interesting package with some useful features outside of the windroses. I was able to install the package (thank you for supporting Fedora), but am having a few issues. When I try to load the package using Juno, it hangs indefinitely for some reason. It precompiles in the Julia terminal, but whenever I try to plot I get

```julia
could not load library "libgmt"
libgmt.so: cannot open shared object file: No such file or directory

```

When I run the .sh scripts from the command line in the test suite, they throw the error:

```julia
psrose: Error: Unrecognized option -J

```

If I delete the J option things seem to work from the bash shell, so maybe that test code is just outdated?

So the install seems to work, but I can’t seem to get the Julia package running properly (let me know if I should open a new thread for that). It seems like a Fedora / path issue, but I am not sure where libgmt is, or how to tell the package where it is.

Thanks-

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [May 27, 2020, 7:43pm UTC](https://discourse.julialang.org/t/how-to-make-a-wind-rose-in-julia/40229/6 "2020-05-27T19:43:07Z")

</div>

That’s a unix thing. When the GMT shared libraries are not stored in standard places one must help the OS. In linux it works setting the `LD_LIBRARY_PATH` to point to the shared lib dir. A more general solution is like explained in the readme page. Add this to startup.jl

```julia
using Libdl
push!(Libdl.DL_LOAD_PATH, "/path/to/gmt/lib")

```

I use it in Visual Studio Code (Windows) with no problems.

---

<div class="post-metadata">

**Author:** ![scone](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@scone](https://discourse.julialang.org/u/scone)\
**Post date:** [May 27, 2020, 8:06pm UTC](https://discourse.julialang.org/t/how-to-make-a-wind-rose-in-julia/40229/7 "2020-05-27T20:06:05Z")

</div>

Ahh, I saw that, but though it might be mac specific. The only libgmt I can find is /lib64/libgmt.so.5, but when I added the above to startup.jl I get the same error. Seems like it is looking for libgmt.so and the 5 is throwing it off?

---

<div class="post-metadata">

**Author:** ![anowacki](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/anowacki/32/17375_2.png) [@anowacki](https://discourse.julialang.org/u/anowacki)\
**Post date:** [May 27, 2020, 9:16pm UTC](https://discourse.julialang.org/t/how-to-make-a-wind-rose-in-julia/40229/8 "2020-05-27T21:16:49Z")

</div>

Whilst the GMT route is the best way to go long term, in dire straits you could use the polar histogram plotting function in [an old repo of mine](https://github.com/anowacki/assorted-julia-modules) (see instructions in the readme file there).

```julia
julia> using CircPlot

julia> θ = 2π.*rand(10_000);

julia> cplot_histogram(θ, 2π/30)

```

will give you this:  
 ![basic_polar_hist](https://global.discourse-cdn.com/julialang/original/3X/6/8/68bc0e85d774a197e60e42614e5ed956252c2907.png)  
and you can tweak the appearance using the usual Plots keywords:

```julia
julia> cplot_histogram(θ, 2π/30, showaxis=false, grid=false, line=(:red,1), fill=(:blue, 0.5), circ=(lc=:black, fill=nothing))

```

giving  
 ![better_polar_hist](https://global.discourse-cdn.com/julialang/original/3X/a/e/ae16410b73ccc27a0ea2366a5795da186eb6d87b.png)

(Note that passing a named tuple, `Dict`, etc. to the `circ` keyword argument sets the plotting style of the outer circle.)

The docstring describes the usage:

```julia
help?> cplot_histogram
search: cplot_histogram

    cplot_histogram(a, binwidth, degrees=false; azimuth=false, axial=false, weights=ones(length(a)), circ=nothing; kwargs...) -> ::Plots.Plot

Plot a polar histogram of a set of angles `a` using bins `binwidth` wide.
`binwidth` should be given in the same convention (radians or °) as the data.
If π (or 180°) is not an integer multiple of `binwidth`, then the nearest value
for which this is true is selected.

Use `azimuth=true` to plot angles clockwise from north.

Use `axial=true` if data are π-ambiguous (i.e., are orientational rather than
directional data).

`weights` must have the same length as `a`, and if passed in will scale each
point `i` by `weights[i]`.

Set options for the surrounding circle using `circ=Dict(:opt=>val)`, where
the keys and values in the Dict will be passed to Plots for plotting the circle
shape around the plot.

Additional keyword arguments `kwargs...` are passed to `Plots.plot()` when
plotting the bars.

```

Ideally this should be implemented as a recipe, in [StatsPlots](https://github.com/JuliaPlots/StatsPlots.jl) or similar, but as yet there aren’t many directional distributions or measures implemented in [Distributions](https://github.com/JuliaStats/Distributions.jl) nor tools for these in [StatsBase](https://github.com/JuliaStats/StatsBase.jl). There is some very basic circular statistics stuff in [CircStats](https://github.com/anowacki/CircStats.jl).

**Edit** : I should say by way of explanation that you will want to use the `weights` keyword argument and set the binwidth to match the bar locations you need, with one point per bin and the bar length specified by the respective value in `weights`:

```
cplot_histogram(theta, step(theta), weights=r, azimuth=true, circ=(lw=1, fill=nothing), showaxis=false, grid=false)

```

![windrose](https://global.discourse-cdn.com/julialang/original/3X/2/e/2ea61545724d3688e6d61451ba6edfa4fb56b080.png)

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [May 27, 2020, 9:43pm UTC](https://discourse.julialang.org/t/how-to-make-a-wind-rose-in-julia/40229/9 "2020-05-27T21:43:06Z")

</div>

For the Travis CI (a Ubuntu machine) I just do

```julia
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$HOME/gmt/lib"

```

(`HOME/gmt/lib` because it’s there that it gets installed).  
Other people have reported this type of problem and the solution has always been either the `LD_LIBRARY_PATH` for Linux or the `setup.jl` for Mac & Linux  
So, in your case perhaps

```julia
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/lib64"

```

---

<div class="post-metadata">

**Author:** ![jmkuhn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmkuhn/32/2090_2.png) [@jmkuhn](https://discourse.julialang.org/u/jmkuhn)\
**Post date:** [May 27, 2020, 11:03pm UTC](https://discourse.julialang.org/t/how-to-make-a-wind-rose-in-julia/40229/10 "2020-05-27T23:03:50Z")

</div>

I have used the command line version of GMT quite a bit but I’m still a novice with the Julia interface. This should get you started.

```julia
using GMT

theta = range(0, stop = 1.5π, length = 100)
r = abs.(0.1 * randn(100) + sin.(3 * theta))
rose([r theta.*180/π], region=[0 1.4 0 360], A=270/99, frame="xg0.2",
    L="270,90,180,0", pen=(:thin, :blue), fill=:orange, fmt=:png, show=true)

```

 ![rose1](https://global.discourse-cdn.com/julialang/original/3X/c/5/c5dc190f251a99d271e1d674c14324e4093dd7f1.png)

---

<div class="post-metadata">

**Author:** ![scone](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@scone](https://discourse.julialang.org/u/scone)\
**Post date:** [May 27, 2020, 11:15pm UTC](https://discourse.julialang.org/t/how-to-make-a-wind-rose-in-julia/40229/11 "2020-05-27T23:15:20Z")

</div>

Same error - for some reason the julia package can’t find it. I installed from the fedora repo, I’ll try the binary package and see if that makes a difference - will let you know…

---

<div class="post-metadata">

**Author:** ![scone](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@scone](https://discourse.julialang.org/u/scone)\
**Post date:** [May 27, 2020, 11:26pm UTC](https://discourse.julialang.org/t/how-to-make-a-wind-rose-in-julia/40229/12 "2020-05-27T23:26:20Z")

</div>

Also thanks for the lead on this code. I might dig into it tomorrow if I can’t get GMT working…

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [May 27, 2020, 11:26pm UTC](https://discourse.julialang.org/t/how-to-make-a-wind-rose-in-julia/40229/13 "2020-05-27T23:26:36Z")

</div>

If you run in command line `gmt --show-bindir` it will tell you where the gmt executable is located. You can then run `ldd`` on it ad see where the dependencies are. For example for my WSL version I get

```julia
ldd gmt
...
libgmt.so.6 => /home/j/programs/lib/libgmt.so.6
...

```

`so.6` possibly because I’m building it from source (master).

---

<div class="post-metadata">

**Author:** ![scone](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@scone](https://discourse.julialang.org/u/scone)\
**Post date:** [May 27, 2020, 11:37pm UTC](https://discourse.julialang.org/t/how-to-make-a-wind-rose-in-julia/40229/14 "2020-05-27T23:37:59Z")

</div>

Yeah, that gives me the same as before:

```julia
libgmt.so.5 => /lib64/libgmt.so.5 (0x00007fb76a52b000)

```

Let me reboot and maybe this will magically fix itself…

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [May 27, 2020, 11:46pm UTC](https://discourse.julialang.org/t/how-to-make-a-wind-rose-in-julia/40229/15 "2020-05-27T23:46:48Z")

</div>

Does GMT run from the command line? A simple test is to type just  
`psxy`  
If it prints the online help it means it’s working fine. If not you may want to post for help in the [GMT forum](https://forum.generic-mapping-tools.org/)

---

<div class="post-metadata">

**Author:** ![scone](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@scone](https://discourse.julialang.org/u/scone)\
**Post date:** [May 27, 2020, 11:52pm UTC](https://discourse.julialang.org/t/how-to-make-a-wind-rose-in-julia/40229/16 "2020-05-27T23:52:15Z")

</div>

That seems to be an issue. psxy doesn’t run, but gmt does. So maybe my install is flawed, even though I can sort of run some of the test scripts. I will have to work on this more tomorrow and report back. Thanks for all your help!

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [May 28, 2020, 12:04am UTC](https://discourse.julialang.org/t/how-to-make-a-wind-rose-in-julia/40229/17 "2020-05-28T00:04:52Z")

</div>

Sorry, my mistake. Now by default one have to run `gmt module` (e.g. `gmt psxy`) and if that runs it means there is no problem with your GMT installation. We can continue this tomorrow in GMT forum since t’s no longer a Julia question.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [May 28, 2020, 12:47am UTC](https://discourse.julialang.org/t/how-to-make-a-wind-rose-in-julia/40229/18 "2020-05-28T00:47:09Z")

</div>

Can’t you just draw the bars basically by hand on the polar graph?

---

<div class="post-metadata">

**Author:** ![scone](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@scone](https://discourse.julialang.org/u/scone)\
**Post date:** [May 28, 2020, 2:30am UTC](https://discourse.julialang.org/t/how-to-make-a-wind-rose-in-julia/40229/19 "2020-05-28T02:30:02Z")

</div>

You have no idea how happy I would be to go back to the days of using a drafting table! But seriously, I am not really sure what you mean by “by hand”. I was planning to write some code bin everything, but my main concerns were that I can’t seem to reverse/rotate the axis, display labels properly, plot from an radius that is not zero, get the bars to fill. Its a task that definitely deserves “canned code”. I have been digging further, and it looks like the PGFPlots backend might actually work for this, I was just avoiding it because it is very slow and doesn’t work well with Juno in my experience.

---

<div class="post-metadata">

**Author:** ![tamasgal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamasgal/32/27946_2.png) [@tamasgal](https://discourse.julialang.org/u/tamasgal)\
**Post date:** [May 28, 2020, 7:25am UTC](https://discourse.julialang.org/t/how-to-make-a-wind-rose-in-julia/40229/20 "2020-05-28T07:25:47Z")

</div>

> [@scone](#):
>
> The only libgmt I can find is /lib64/libgmt.so.5, but when I added the above to startup.jl I get the same error. Seems like it is looking for libgmt.so and the 5 is throwing it off?

You can try quick and dirty by doing `sudo ln -s /lib64/libgmt.so.5 /lib64/libgmt.so`

This will not hurt anyone but keep in mind to update the link once you update GMT (so.6 etc.).

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [June 2, 2020, 1:29pm UTC](https://discourse.julialang.org/t/how-to-make-a-wind-rose-in-julia/40229/21 "2020-06-02T13:29:28Z")

</div>

It would be nice if you can update GMT.jl and try again. I’ve came up with what I think is a general solution to those `could not load library "libgmt"` errors in all \*nixes

[Next page](https://discourse.julialang.org/t/how-to-make-a-wind-rose-in-julia/40229.md?page=2)
