Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

Any suggestions ?

share|improve this question
    
    
I forgot to ask, by wind rose you mean the left graph? –  Kuba Aug 28 '13 at 7:04
    
Also, in what form is the data you have to work with? –  Kuba Aug 28 '13 at 7:32
3  
From what I've seen about your right graph in internet you may also be interested in SectorChart. –  Kuba Aug 28 '13 at 8:25
1  
Could be something useful to you here: stackoverflow.com/q/7867755/879601 –  Chris Degnen Aug 28 '13 at 20:09
add comment

4 Answers

up vote 17 down vote accepted

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

share|improve this answer
    
Why not use PlotMarkers -> Automatic alongside Joined -> True, then you only have to invoke ListPolarPlot once. –  rcollyer Aug 28 '13 at 12:42
    
@Kuba Thanks. Looks much better now. –  David Carraher Aug 28 '13 at 13:14
    
I like this~ Thanks to all~~ –  bushiwo Aug 30 '13 at 5:17
add comment

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 -> Arrowheads@.07]

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 -> Arrowheads@.07,
         Ticks -> None, PlotRange -> 5]

enter image description here

share|improve this answer
    
Next time I upvote one of your answers, I'll wait for at least 3 more updates before doing so :) –  Pinguin Dirk Aug 28 '13 at 7:11
    
@PinguinDirk now it's not worth it? :( :) –  Kuba Aug 28 '13 at 7:11
1  
@PinguinDirk I'm sorry for the next update :P –  Kuba Aug 28 '13 at 19:13
1  
haha, ok, well, for +17 you better get some work done! –  Pinguin Dirk Aug 28 '13 at 19:15
1  
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. –  Pickett Aug 29 '13 at 10:10
show 5 more comments

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

share|improve this answer
    
@Kuba I updated according to your specifications. Much better! Ty. –  Pickett Aug 29 '13 at 14:56
    
Indeed. And again, great idea! ;) –  Kuba Aug 29 '13 at 15:50
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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