I have written a code that plots a windrose. However, I need to specify wind speeds at a particular color. I am getting an error “Error is RGBA sequence should have length 3 or 4”. Any help would be great.
import pandas as pd
import regex as re
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
#import matplotlib.cm as cm
from windrose import WindroseAxes
# count the frequency of times a specific direction occurred (0, 22.5, 45.0, 67.0, 90.0, 112.5, 135.0, 157.5, 180.0, 202.5, 225.0, 247.5, 270.0, 292.5, 315.0, 337.5)
# given a specific month, hour, over x amount of years
# one solution will include an ouput text file
# second solution will include a wind rose plot of wnd_dir, wnd_spd,
# second solution will include title of station time (e.g. hours 0-23) for month xxxx-xxxx
df = pd.read_excel("A23AA_wnd_rose.xlsx",usecols='C:D')
# function
def get_station(file_name: str):
return re.findall(r'\d*', file_name)
# function call
station_name = get_station("A23AA_wnd_rose.xlsx")
# WD and WS data sets and calculations
WS = df['Column4'][3:].to_list()
WD = df['Column5'][3:].to_list()
WS = [float(s) for s in WS]
WD = [float(d) for d in WD]
avg_WS = np.nanmean(WS)
avg_WD = np.nanmean(WD)
std_WS = np.std(WS)
std_WD = np.std(WD)
bins = [0, 4, 8, 12]
def get_color(v):
if v < 3:
return 'k'
elif v > 4 < 8:
return 'b'
elif v > 8 < 12:
return 'y'
elif v > 12:
return 'r'
colors = [get_color(v) for v in WS]
ax = WindroseAxes.from_ax()
ax.bar(WD,WS, normed = True, opening = 0.8, color = colors, edgecolor = "white", bins = bins)
ax.set_legend()
plt.title('Meda 23 January 2022')
plt.show()
Error is below
windrose\windrose.py:667: UserWarning: Setting the 'color' property will override the edgecolor or facecolor properties.
patch = mpl.patches.Rectangle(
Traceback (most recent call last):
runpy.py", line 198, in _run_module_as_main
return _run_code(code, main_globals, None,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
runpy.py", line 88, in _run_code
exec(code, run_globals)
debugpy\launcher/../..\debugpy\__main__.py", line 39, in <module>
cli.main()
debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 430, in main
run()
debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 284, in run_file
runpy.run_path(target, run_name="__main__")
pydevd\_pydevd_bundle\pydevd_runpy.py", line 321, in run_path
return _run_module_code(code, init_globals, run_name,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
F_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code
_run_code(code, mod_globals, init_globals,
debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code
exec(code, run_globals)
Wind_Rose.py", line 52, in <module>
ax.bar(WD,WS, normed = True, opening = 0.8, color = colors, edgecolor = "white", bins = bins)
windrose\windrose.py", line 667, in bar
patch = mpl.patches.Rectangle(
^^^^^^^^^^^^^^^^^^^^^^
matplotlib\patches.py", line 718, in __init__
super().__init__(**kwargs)
matplotlib\patches.py", line 81, in __init__
self.set_color(color)
matplotlib\patches.py", line 371, in set_color
self.set_facecolor(c)
matplotlib\patches.py", line 356, in set_facecolor
self._set_facecolor(color)
matplotlib\patches.py", line 344, in _set_facecolor
self._facecolor = colors.to_rgba(color, alpha)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
matplotlib\colors.py", line 302, in to_rgba
rgba = _to_rgba_no_colorcycle(c, alpha)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
matplotlib\colors.py", line 393, in _to_rgba_no_colorcycle
raise ValueError("RGBA sequence should have length 3 or 4")
ValueError: RGBA sequence should have length 3 or 4
wx_climo>