Skip to content

Instantly share code, notes, and snippets.

Last active January 19, 2024 05:57
  • Star 28 You must be signed in to star a gist
  • Fork 13 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save phobson/41b41bdd157a2bcf6e14 to your computer and use it in GitHub Desktop.
Making a wind rose in pandas/matplotlib
Display the source blob
Display the rendered blob
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Copy link

r-melo commented Apr 22, 2018

I ran across an issue. If my data don't have wind information in a specific direction the dataframe 'rose' ends with an incorrect number of rows, without any information for the missing directions. In order to plot it correctly you need rows for these directions filled with zeroes. I solved with this little code right after creating the 'rose' dataframe:

directions = np.arange(0, 360, 15)
for i in directions:
    if i not in rose.index:
        rose = rose.reindex(rose.index.values.tolist()+[i])

rose = rose.sort_index().fillna(0)

Copy link

Hi thanks for this great example! I try to plot my weewx data, which is pretty similar table.

But plotting the rose throws an exception which I don't understand

ValueError: shape mismatch: objects cannot be broadcast to a single shape
..., rosedata[c1].values,

Because I don't understand this part well enough, could you point me, if this rose object looks ok for you?

<class 'pandas.core.frame.DataFrame'>
CategoricalIndex: 25 entries, 0.0 to 360.0
Data columns (total 8 columns):
 #   Column       Non-Null Count  Dtype  
---  ------       --------------  -----  
 0   calm         25 non-null     float64
 1   0 - 5 m/s    25 non-null     float64
 2   5 - 10 m/s   25 non-null     float64
 3   10 - 15 m/s  25 non-null     float64
 4   15 - 20 m/s  25 non-null     float64
 5   20 - 25 m/s  25 non-null     float64
 6   25 - 30 m/s  25 non-null     float64
 7   >30 m/s      25 non-null     float64
dtypes: float64(8)
memory usage: 2.4 KB

Copy link

phobson commented Feb 29, 2020

@Matthias84 -- that's not enough info for me to provide manful advice. I recommend you look at cloudside, where I put all of this into a single function

Copy link

I'm getting:
sta = metar.WeatherStation('KPDX')
AttributeError: module 'metar' has no attribute 'WeatherStation'

Copy link

phobson commented Jun 14, 2021

I'm getting:
sta = metar.WeatherStation('KPDX')
AttributeError: module 'metar' has no attribute 'WeatherStation'

@BDJensen -- checkout -- that's where all of this stuff lives now. More to the point, the purpose of that section of code was to download the data. You can skip it and get the data anyway you want.

Copy link

Great code, thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment