Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wind rose axis #151

Closed
Umercia opened this issue Dec 1, 2020 · 15 comments
Closed

wind rose axis #151

Umercia opened this issue Dec 1, 2020 · 15 comments

Comments

@Umercia
Copy link

Umercia commented Dec 1, 2020

Hi,

It seems that the default directions along the axis circle is not correct anymore. 0° pointing to East
To use the example in the example notebook:

%matplotlib inline
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
import matplotlib.cm as cm
import numpy as np
from math import pi
from windrose import WindroseAxes

N = 500
ws = np.random.random(N)*6
wd = np.random.random(N)*360
df = pd.DataFrame({"speed": ws, "direction": wd})

ax = WindroseAxes.from_ax()
ax.bar(df.direction, df.speed, normed=True, opening=0.8, edgecolor='white')
ax.set_legend()

2020-12-01_11h05_02

@rngadam
Copy link

rngadam commented Dec 25, 2020

Same here with Windrose 1.6.8:

Screenshot 2020-12-25 at 2 11 02 PM

@rngadam
Copy link

rngadam commented Dec 25, 2020

Duplicate of #147 ?

@waldowda
Copy link

I see the same thing and numbers not directions are labeled. I had to add the axes presumably setting the '0' to E as compensation but the labeling seems off by 90° as noted above.

ax.set_xticklabels(['E', 'NE','N', 'NW', 'W', 'SW', 'S', 'SE'])

@FFT1368
Copy link

FFT1368 commented Feb 26, 2021

This is an important issue in which the theta labels in windrose are incorrect. for solving it you can type this line in your code.
I hope it be useful for you ;)

Solution:

ax.set_xticklabels((90, 45, 0, 315, 270, 225, 180, 135))

@FFT1368
Copy link

FFT1368 commented Feb 26, 2021

Complete code after solution:

from windrose import WindroseAxes
from matplotlib import pyplot as plt
import matplotlib.cm as cm
import numpy as np
plt.figure()

ws = np.random.random(500) * 25
wd = np.random.random(500) * 360
ax = WindroseAxes.from_ax()
plt.style.use('fast')
ax.bar(wd, ws, nsector= 36,opening=0.94, bins=np.arange(0, 31, 5),edgecolor='gray',lw=0.1)
ax.set_xticklabels([90, 45, 0, 315, 270, 225, 180, 135])

ax.set_legend()
ax.set_title("Wind Rose")

plt.show()

@FFT1368
Copy link

FFT1368 commented Feb 26, 2021

And for having all the grids and numbers every 10 degrees you can use this improved version:

from windrose import WindroseAxes
from matplotlib import pyplot as plt
import matplotlib.cm as cm
import numpy as np
plt.figure()

ws = np.random.random(500) * 25
wd = np.random.random(500) * 360
ax = WindroseAxes.from_ax()
plt.style.use('fast')
ax.bar(wd, ws, nsector= 36,opening=0.94, bins=np.arange(0, 31, 5),edgecolor='gray',lw=0.1)
ax.set_thetagrids(range(0,360,10),[90, 80, 70, 60, 50, 40, 30, 20, 10, 0, 350, 340, 330, 320, 310, 300, 290, 280, 270, 260, 250, 240, 230, 220, 210, 200, 190, 180, 170, 160, 150, 140, 130, 120, 110, 100])
ax.set_theta_zero_location('W', offset=-90)
ax.set_theta_direction(-1)

ax.set_legend()
ax.set_title("Wind Rose")

plt.show()

@swartmilan
Copy link

@FFT1368 Thank you for your post, I encountered this same issue and fixed it myself, only thinking ofo coming to the known issues section after the fact :/

In your solution, are you keeping the 'W' direction at the theta = 0 location on the polar plot? What is your reason for doing this? Another solution would be to set the theta_zero_location to 'N' and then make the offset=0, with the direction going clockwise of course.

Code below (incomplete code, showing only additions to the 'usual' windrose plot things):
matplotlib.projections.polar.PolarAxes.set_theta_zero_location(ax, loc="N", offset=0.0) matplotlib.projections.polar.PolarAxes.set_theta_direction(ax, direction=-1) matplotlib.projections.polar.PolarAxes.set_thetagrids(ax, angles=[0,45,90,135,180,225,270,315], labels=["N","NE","E","SE","S","SW","W","NW"], fmt='str')

Example:
image

Is there a reason you did not go this route that I am missing? I'm thinking there might be issues with the labels only moving with the data remaining plotted in the same locations for instance. Otherwise if it works the same then 'N' in the theta=0 location would be preferable right?

@FFT1368
Copy link

FFT1368 commented Apr 1, 2021

@swartmilan
Dear Mr. swartmilan,
I kept theta=0 on West for our company purpose. But if you need to label North as Theta=0 you can use this code for labeling.
Please find the program below:

from windrose import WindroseAxes
from matplotlib import pyplot as plt
import matplotlib.cm as cm
import numpy as np


ws = np.random.random(500) * 25
wd = np.random.random(500) * 360
ax = WindroseAxes.from_ax()
plt.style.use('fast')
ax.bar(wd, ws, nsector= 36,opening=0.94, bins=np.arange(0, 31, 5),edgecolor='gray',lw=0.1)
ax.set_thetagrids(range(0,360,10),[90, 80, 70, 60, 50, 40, 30, 20, 10, 0, 350, 340, 330, 320, 310, 300, 290, 280, 270, 260, 250, 240, 230, 220, 210, 200, 190, 180, 170, 160, 150, 140, 130, 120, 110, 100])
ax.set_theta_zero_location('W', offset=-180)


ax.set_legend(loc=(-0.08, -0.08))
ax.set_title("Wind Rose")

plt.show()

Capture22

@cheikhnatm
Copy link

Hello @FFT1368, I was wondering which parameters control the values of the frequency ? to have them spaced evenly ? in this picture for example.

Capture

Thank you in advance

@swartmilan
Copy link

@FFT1368 Thank you for responding!
I'd like to check my understanding of the set_theta_zero_location function with you if you wouldn't mind.
So the default in matplotlib projections is theta=0° at the EAST location, but most windmasts measure a 0° wind direction at NORTH (I'm presuming your companies data has theta=0° at the WEST location?); so to have matplotlib plot the 0° data at the NORTH location in my case, one has to use the offset= kwarg; does the loc= kwarg then just give the label for the new theta=0° location then?
Essentially, the offset kwarg is the main one that determines the rotation of the data relative to EAST?

@cheikhnatm I think you can go into the windrose.py package where it is installed locally and change the radii label spacing where it calculates it radii=np.linspace(0, rmax, N + 1)
Something like

def set_radii_angle(self, **kwargs):
  N = 6
  rmax = 12
  radii = np.linspace(0, rmax, N + 1)

let me know if this works please :)

@ocefpaf
Copy link
Collaborator

ocefpaf commented May 6, 2022

This was fixed in #165

Please open a new issue if this resurfaces.

@ocefpaf ocefpaf closed this as completed May 6, 2022
@PurveshPatel96
Copy link

Hello @FFT1368, I was wondering which parameters control the values of the frequency ? to have them spaced evenly ? in this picture for example.

Capture

Thank you in advance

@PurveshPatel96
Copy link

How do you mentioned the % value as a normed/frequency ?

thank you in advance

@robertburry
Copy link

And for having all the grids and numbers every 10 degrees you can use this improved version:

from windrose import WindroseAxes from matplotlib import pyplot as plt import matplotlib.cm as cm import numpy as np plt.figure()

ws = np.random.random(500) * 25 wd = np.random.random(500) * 360 ax = WindroseAxes.from_ax() plt.style.use('fast') ax.bar(wd, ws, nsector= 36,opening=0.94, bins=np.arange(0, 31, 5),edgecolor='gray',lw=0.1) ax.set_thetagrids(range(0,360,10),[90, 80, 70, 60, 50, 40, 30, 20, 10, 0, 350, 340, 330, 320, 310, 300, 290, 280, 270, 260, 250, 240, 230, 220, 210, 200, 190, 180, 170, 160, 150, 140, 130, 120, 110, 100]) ax.set_theta_zero_location('W', offset=-90) ax.set_theta_direction(-1)

ax.set_legend() ax.set_title("Wind Rose")

plt.show()

I had a similar issue as the original poster. This solution did help (I needed to remove the ax.set_theta_direction(-1) for my dataset). But I figured I would add what I ended up doing to make this abit easier for some.

Instead of constructing the list myself I wrote it into a List Comprehension:
[(i + 360) if i < 0 else i for i in range(90,-270,-10)])

so combined it looks like:
ax.set_thetagrids(range(0,360,10),[(_+360) if _ < 0 else _ for _ in range(90,-270,-10)])

Which gave me the result I was looking for.
output

@ocefpaf
Copy link
Collaborator

ocefpaf commented Mar 24, 2023

@robertburry this is a closed issue but your comment/code is nice and valid. Do you mind opening a new one with the updated info?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants