Make a wind rose chart with Plotly Express
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

I'd love to have a wind rose chart made with Plotly Express just like the one shown here. You can see a graph and the data here. This will involve some data manipulation to fill it in, and to convert the data from degrees to the same cardinal directions shown in the Plotly example. Please use the same buckets for data that the Plotly example has, not the ones in the graph and data.

Hello does it have to be a one shot graph ? or do you want to be able to give data to a script that generates the HTML file and all the conversions are done automatically ?
kerncy 1 month ago
It'd be great to have a Python script that contains the whole thing; so if you could share a gist that reads the data into a pandas df then creates the graph that'd be great. Thanks for clarifying.
msund 1 month ago
OK I see, Just to be sure that I'm in the right direction, here is a first manual transformation of the data that regroups (36) direction to (16) cardinal points, sum the regrouped values(for example E is the sum of direction 070-090, 080-100 and 090-110), and set them as a graph : https://web.kern-info.eu/wind.html is it something like that that you want ?
kerncy 1 month ago
Looks great yep.
msund 1 month ago
awarded to kerncy

Crowdsource coding tasks.

1 Solution

Winning solution

Hi

Here is my solution, it can be download here : http://web.kern-info.eu/windgraph.zip

To use it just run

python3 wind.py data.txt

data.txt is the raw data file as the one provided in your sample. I suppose that format will never change (regarding comments, separators, ...). It dynaminc in terms of number of lines in the file, only directions should always be kept as "begin-end". The number of Strenght is dynamic to. First line of data must be the headers representing the strenghts.

It will generate a wind_out.html file as output that will contain your graph.

I consider my "conversion" process a little hacky and I assume that it should be possible to be done in a better way using pandas dataframe instead of python array.

Process is the following :

  • read the file by converting the provided degrees to cardinality. Each cardinality represents a subset of degrees. If the mean deegrees (for exampe 030-050, mean is 40) of your line is inside the interval of the cardinal, than this line is associated to this cardinality
  • next step, is to merge frequencies that shares the same cardinal using sumElements function
  • final step, generate a json object that will be converted to a dataframe and visualized using plotly

Do not hesitate if you have any question

Hey there, thanks so much. I assume this works, sounds right. I'm the worst; is there any chance you could host this in Colab or a similar environment and make the graph for it? I don't have Python or anything set up on my work computer so can't really run it. It'd be great to be able to eyeball it. For example: https://colab.research.google.com/drive/1EB7MI_3gzAR1gFwPPO27YU9uYzE_odSu
msund 1 month ago
Hi, I don't know how colab works. So I put the data into a repl.it project : https://repl.it/@CyrilKern/Windrose In the main.py file you can modifiy the "process" function to pass an input and output file. The HTML will be generated in the root directory of the project, you will then be able to download it. Is it ok for you ?
kerncy 1 month ago
Here is your colab link : https://colab.research.google.com/drive/1tukdj8NscMJmmq71Nlf7iJS5iBxAFYDq?usp=sharing In fact it was really simple to use. Just import your file, set the path in the process function and you will be able to run it and display the generated graph :)
kerncy 1 month ago