Reputation: 513
I have this df
:
wind speed - Km/Hr Wind Dir counts Frequency
0 0 - <2 E 1278 0.018459
1 0 - <2 ENE 1889 0.027284
2 0 - <2 ESE 1057 0.015267
3 0 - <2 N 1600 0.023110
4 0 - <2 NE 2172 0.031371
............. ...... ... .... ........
I want to plot a wind rose so i wrote this code:
Original code: https://plotly.com/python/wind-rose-charts/#wind-rose-chart-with-plotly-express
import plotly.express as px
fig = px.bar_polar(df, r="Frequency", theta="Wind Dir",
color="wind speed - Km/Hr", template="plotly_dark",
color_discrete_sequence= px.colors.sequential.Plasma_r)
fig.show()
And when i run the code the figure is not shown, but a variable called fig is created. So i right click in the variable (in spyder console) and i click in the option "view with the object explorer" but the figure does not appear anyways.
Would you mind to help me?
Thanks in advance.
Upvotes: 0
Views: 190
Reputation: 28585
It would work if you ran it under something like Jupyter. But since it Spyder, depends if you want it as a static image or interactive. But you need to look at/use renderers. For example, you can open in the browser as an html file and keep the interactive/hover parts:
import pandas as pd
df = pd.DataFrame([['0 - <2','E',1278,0.018459],
['0 - <2','ENE',1889,0.027284],
['0 - <2','ESE',1057,0.015267],
['0 - <2','N',1600,0.023110],
['0 - <2','NE',2172,0.031371]],columns = ['wind speed - Km/Hr','Wind Dir','counts','Frequency'])
import plotly.express as px
fig = px.bar_polar(df, r="Frequency", theta="Wind Dir",
color="wind speed - Km/Hr", template="plotly_dark",
color_discrete_sequence= px.colors.sequential.Plasma_r)
fig.write_html("C:/test/file.html")
Output:
Upvotes: 1