python-windrose / windrose

A Python Matplotlib, Numpy library to manage wind data, draw windrose (also known as a polar rose plot), draw probability density function and fit Weibull distribution
https://python-windrose.github.io/windrose
Other
339 stars 133 forks source link

custom binning of wind direction direction #273

Closed vimalaathythan-v2w closed 4 months ago

vimalaathythan-v2w commented 4 months ago

Use case: need to bin the wind direction the binning interval is 10 degree. so for 360 degree we will have 36 bars . how to set the no of bars in the wind rose?

  1. I read the wind rose documentation. but could not find a parameter to define the no bins for wind direction.
  2. adjusted_wd = np.where(wd < 0, wd + 360, wd) # Adjust negative angles to be positive ax.bar(adjusted_wd, ws, bins=np.arange(0, 361, 10), normed=True, opening=0.8, edgecolor='white') I modified the bin parameter which bins the wind speed not wind direction. Any experts here can help me?
jkittner commented 4 months ago

You need to set nsector=36 as shown in this example in the documentation: https://python-windrose.github.io/windrose/usage-output.html#...or-without-filled-regions using nsector=16.

It is also listed under "Optional:" a bit further down in the docs.

This should do what you want:

from windrose import WindroseAxes
import numpy as np

ws = np.random.random(500) * 6
wd = np.random.random(500) * 360

ax = WindroseAxes.from_ax()
ax.bar(wd, ws, normed=True, opening=0.8, edgecolor='white', nsector=36)
ax.set_legend()

I don't think it's easy to read though - 16 is the sweetspot imo.

grafik

vimalaathythan-v2w commented 4 months ago

Hi ,

Thanks for the quick and helpful response. Setting nsector=36 works perfectly! I'll keep your readability tip about 16 in mind.

Much appreciated!

Thanks & Regards, Vimalaathythan M.


From: Jonas Kittner @.> Sent: Tuesday, June 25, 2024 4:18 AM To: python-windrose/windrose @.> Cc: Vimalaathythan Manivasakam @.>; Author @.> Subject: Re: [python-windrose/windrose] custom binning of wind direction direction (Issue #273)

You need to set nsector=36 as shown in this example in the documentation: https://python-windrose.github.io/windrose/usage-output.html#...or-without-filled-regions using nsector=16.

It is also listed under "Optional:" a bit further down in the docs.

This should do what you want:

from windrose import WindroseAxes import numpy as np

ws = np.random.random(500) 6 wd = np.random.random(500) 360

ax = WindroseAxes.from_ax() ax.bar(wd, ws, normed=True, opening=0.8, edgecolor='white', nsector=36) ax.set_legend()

I don't think it's easy to read though - 16 is the sweetspot imo.

grafik.png (view on web)https://github.com/python-windrose/windrose/assets/54631600/04bb77c9-8caa-452e-ad91-b8596d2a9aec

— Reply to this email directly, view it on GitHubhttps://github.com/python-windrose/windrose/issues/273#issuecomment-2187549470, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BIQGR7HMXN3AXB2OZP53RDDZJCO2TAVCNFSM6AAAAABJZRLIESVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOBXGU2DSNBXGA. You are receiving this because you authored the thread.Message ID: @.***>

vimalaathythan-v2w commented 4 months ago

@.*** would like to recall the message, "Re: [python-windrose/windrose] custom binning of wind direction direction (Issue #273)".