1

The first part of code is code from plotly website and it shows what i would like to make with my own data available.

import plotly.express as px
import pandas as pd

fig= px.bar_polar(df2, r="frequency", theta = "direction",
                 color = "strength", template = "plotly_dark",
                 color_discrete_sequence = px.colors.sequential.Plasma_r)
fig.show()

Desired graph: What it should look like

This is my code so far:

import plotly.express as px
import pandas as pd

df = pd.read_csv (r"Lidar_final_corrected.csv")
print(df)
      wind_dir  Windspeed
0       227.35       2.12
1       233.41       1.65
2       227.75       1.52
3       217.75       1.71
4       204.64       2.21
...        ...        ...
3336    222.33      17.89
3337    221.52      17.21
3338    219.37      15.45
3339    217.23      16.09
3340    218.31      16.18

[3341 rows x 2 columns]

fig= px.bar_polar(df,theta = "wind_dir",
                 color = "wind_dir", template = "plotly_dark",
                 color_discrete_sequence = px.colors.sequential.Plasma_r)
fig.show()

Current output: What it looks like

Now if you look closely you can see that it is plotting something, but the colors are not right. I left out the frequency because I only have two columns to work with. Is there a workaround to make this plot work without the frequency?

(PS: the data is data based on time series so every 10min or 1 min a new entry is in there. I deleted the timestamp because I don't think I need it.)

2
  • Maybe the windrose library comes in handy here? Commented Mar 19, 2020 at 17:41
  • Thanks JohanC i made the windroses for now with windrose library wich is working just fine. But to have a little more interactivity and nicer visuals i would like to move to the plotly version mentioned above. Commented Mar 20, 2020 at 18:09

1 Answer 1

1

you need to do a pandas groupby

grp = df.groupby(["wind_dir", "wind_speed"]).size().reset_index(name="frequency")

as explained in this answer

Then you can use the plotly code same as in the plotly docs!

fig = px.bar_polar(grp, r="frequency", theta="wind_dir",
    color="wind_speed", template="plotly_dark",
    color_discrete_sequence=px.colors.sequential.Plasma_r
)
fig.show()

Happy plotting! (for better results you should bin the wind directions and wind speeds. (at least round them). Example of proper binning: https://community.plotly.com/t/wind-rose-with-wind-speed-m-s-and-direction-deg-data-columns-need-help/33274/5

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.