How to make Wind Rose and Polar Bar Charts in Plotly – Python?

A Plotly is a Python library that is used to design graphs, especially interactive graphs. It can plot various graphs and charts like histogram, barplot, boxplot, spreadplot, and many more. It is mainly used in data analysis as well as financial analysis. plotly is an interactive visualization library.

What is Wind Rose and Polar Bar Charts? 

The wind rose chart are graphical charts that show the speed and direction of winds at a location over a period of time. This chart is represented in circular format and the circle indicates the amount of time that the wind blows from a particular direction. The wind rose chart is also known as the polar bar chart.

Creating Wind Rose Chart

In plotly, a wind rose chart can be made by using the go.Barpolar() method of graph_object class or by px.bar_polar() method of express class.

Syntax: plotly.graph_objects.Barpolar(arg=None,dr=None, dtheta=None,r=None,theta=None)

Syntax: plotly.express.bar_polar(data_frame=None, r=None, theta=None, color=None,)



Example 1:

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

import plotly.express as px
  
# using the wind dataset
df = px.data.wind()
  
fig = px.bar_polar(df, r="strength", theta="direction",
                   color="frequency",)
fig.show()

chevron_right


Output:

Example 2:

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

import plotly.express as px
  
  
df = px.data.tips()
  
fig = px.bar_polar(df, r="total_bill", theta="time",
                   color="sex",)
  
fig.show()

chevron_right


Output:

Example 3:

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

import plotly.graph_objects as go
  
fig = go.Figure()
  
fig.add_trace(go.Barpolar(
    r=[10, 20, 30, 40],
    name='Wind 1',
))
  
fig.add_trace(go.Barpolar(
    r=[40, 20, 50, 10],
    name='Wind 2',
))
  
fig.show()

chevron_right


Output:


Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.