38
$\begingroup$

I am trying to plot wind rose in Mathematica, but have no idea how to do this. Plot

Any suggestions ?

$\endgroup$
2

4 Answers 4

30
$\begingroup$

Edit:

PolarTicks uses the built-in option for "Direction". An earlier version of this answer shows how to manually add PolarTicks.


The following displays the wind rose on the right (with different data points). As rcollyer notes, the data points and joining lines can be both achieved in a single use of ListPolarPlot through PlotMarkers->Automatic. The PlotLabel is from Kuba.

r = Table[{2 t Pi/16, RandomReal[{1, 6}]}, {t, 0, 15}];
ListPolarPlot[Append[r, r[[1]]],
  PlotLabel -> "风向图", BaseStyle -> 14,
  PolarTicks -> {"Direction", Automatic},
  Joined -> True, PlotMarkers -> Automatic, 
  PlotStyle -> {PointSize[Large]}, PolarAxes -> True, 
  PolarGridLines -> {Table[2 k Pi/16, {k, 0, 15}], Automatic}, 
  PolarAxesOrigin -> {Pi/2, 6}]

cardinal directions

$\endgroup$
3
  • $\begingroup$ Why not use PlotMarkers -> Automatic alongside Joined -> True, then you only have to invoke ListPolarPlot once. $\endgroup$
    – rcollyer
    Aug 28, 2013 at 12:42
  • $\begingroup$ @Kuba Thanks. Looks much better now. $\endgroup$
    – DavidC
    Aug 28, 2013 at 13:14
  • $\begingroup$ I like this~ Thanks to all~~ $\endgroup$
    – bushiwo
    Aug 30, 2013 at 5:17
44
$\begingroup$

Edit note: I want to thank to all upvoters, this is really shocking and motivating :). Just to make this answer covering both graphs I've added right graph made with SectorChart like I suggested in comments and to not clone David's solution.

data = RandomReal[{1, 5}, 16];

Left graph: For equally spaced (in angle) measurements it is easier to use Mesh for ParametricPlot:

data2 = ({Cos@#, Sin@#} & /@ Range[0, 15 Pi/8, Pi/8]) data; AppendTo[data2, data2[[1]]];
f = BSplineFunction[data2, SplineDegree -> 1];

g2 = ParametricPlot[(r f[t]), {t, 0, 1}, {r, 0, 1}, BoundaryStyle -> {Thick, Black},
                                  Frame -> False, PlotRangePadding -> .2, PlotRange -> 6
                                  MeshFunctions -> (#3 &), Mesh -> (Length[data2] - 2), 
                                  MeshShading -> {White, Black},  Axes -> True, 
                                  Ticks -> None, AxesStyle -> [email protected]]

Right graph:

data2 = Transpose[{ConstantArray[1, 16], data}];

g1 = SectorChart[data2, PolarTicks -> {"Direction", Automatic}, PlotLabel -> "风向图", 
           BaseStyle -> {15, Bold},  SectorOrigin -> -Pi/16, PolarAxes -> True,
           PolarGridLines -> {Range[Pi/16, 2 Pi, Pi/8], Range[0, Ceiling@Max[data]]}, 
           PolarAxesOrigin -> {(Pi/8 (Position[#, Min@#] &@data-1)])[[1, 1]], 
                               Ceiling@Max[data]},
           ColorFunction -> (Blend["Rainbow", #2] &)]

Row[{g2, g1}]

enter image description here


Old one: works also for not equally spaced points (in angle). Why does ListPolarPlot has no Filling->{0,0} option? :(

Graphics[{EdgeForm@Thick,
          Polygon[Riffle[data2, f[0, 0], {2, -1, 3}] /. f -> List],
          White, 
          Polygon[Riffle[data2, f[0, 0], {3, -1, 3}] /. f -> List]
         },
         Axes -> True, PlotRangePadding -> .2, AxesStyle -> [email protected],
         Ticks -> None, PlotRange -> 5]

enter image description here

$\endgroup$
10
  • $\begingroup$ Next time I upvote one of your answers, I'll wait for at least 3 more updates before doing so :) $\endgroup$ Aug 28, 2013 at 7:11
  • $\begingroup$ @PinguinDirk now it's not worth it? :( :) $\endgroup$
    – Kuba
    Aug 28, 2013 at 7:11
  • 1
    $\begingroup$ @PinguinDirk I'm sorry for the next update :P $\endgroup$
    – Kuba
    Aug 28, 2013 at 19:13
  • 1
    $\begingroup$ haha, ok, well, for +17 you better get some work done! $\endgroup$ Aug 28, 2013 at 19:15
  • 1
    $\begingroup$ Change "data" to "data2" in g1 and add a comment saying that you have to adjust the radial scale manually if you change the data then you'll have my vote as well. $\endgroup$
    – C. E.
    Aug 29, 2013 at 10:10
19
$\begingroup$

Using WeatherData and Kuba's code we can use Mathematica to produce an actual wind rose with real data. This is the function I came up with:

windRose[city_] := Module[{data, total},
  (* Base the wind rose on thirty years of data, as seems to be customary *)
  data = WeatherData[city, "WindDirection", {{1983, 1}, {2013, 1}}];
  data = Select[
    DeleteCases[data /. {{__}, x_} :> x, _Missing], # < 360 &];
  data = HistogramList[data, {22.5}];
  data = data[[2]];
  total = Total[data];
  data = Transpose[{ConstantArray[1, 16], data/total}];

 SectorChart[data, PolarTicks -> {"Direction", Automatic}, 
 PlotLabel -> city, BaseStyle -> {15, Bold}, SectorOrigin -> -Pi/16, 
 PolarGridLines -> {Range[Pi/16, 2 Pi, Pi/8], Automatic}, 
 PolarAxesOrigin -> {(Pi/8 Position[#, Min@#] &@data[[;; , 2]])[[1, 1]], Max@data[[;; , 2]]}, 
 ColorFunction -> (Blend["Rainbow", #2] &), PolarAxes -> True]
  ]

The argument could be a pair of coordinates, a name of a city or a weather station ID. In the end the wind rose will represent the weather station. If we enter a city, Mathematica will choose a weather station in/by that city. So for example:

windRose["Chicago"] (* Chicago, Illinois *)

Chicago

windRose["Gothenburg"] (* Gothenburg, Sweden *)

Gothenburg

$\endgroup$
2
  • $\begingroup$ @Kuba I updated according to your specifications. Much better! Ty. $\endgroup$
    – C. E.
    Aug 29, 2013 at 14:56
  • $\begingroup$ Indeed. And again, great idea! ;) $\endgroup$
    – Kuba
    Aug 29, 2013 at 15:50
11
$\begingroup$

Nothing fancy here, just showing that you can fake Filling in ListPolarPlot by creating a Polygon (with a vertex at the origin) from each line segment:

windrose[data_] := Module[{dat = Append[data, First@data]},
  ListPolarPlot[dat, DataRange -> {0, 2 Pi}, Joined -> True, 
    Ticks -> None, Mesh -> Length[dat] - 2, 
    MeshShading -> {White, Black}, MeshStyle -> None] /. 
   Line[{x__}] :> {Polygon[{x, {0, 0}}], Black, Line[{x}]}]

windrose[RandomReal[{0.3, 1.0}, 16]]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.