windrose icon indicating copy to clipboard operation
windrose copied to clipboard

How to set continuous windrose colorbar!

Open wjjxjd opened this issue 4 years ago • 4 comments

Hi, You do a good job. How to set continuous colorbar like this? Screenshot from 2020-10-26 21-30-24

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


def plotPollutionRoseDemo(value,speed,direction,save_path='demo.png'):
    '''
    np.random.random(500) 产生的是0~1之间的数,相当于归一化处理了
    '''
    fig = plt.figure()
    rect = [0.1, 0.1, 0.8, 0.8]
    hist_ax = plt.Axes(fig,rect)
    hist_ax.bar(np.array([1]), np.array([1]))
    ax=WindroseAxes.from_ax()
    ax.bar(direction,value,normed=True,opening=0.8,bins=[0,5,10,15,20],edgecolor='white')
    #ax.box(direction,speed,normed=True,opening=0.8,bins=np.arange(0, 8, 1),edgecolor='white')
    #wrscatter(direction,value, ax=ax, rmax=None)
    ax.set_legend(loc=4, bbox_to_anchor=(1., -0.07))
    str=['N','N-E','E','S-E','S','S-W','W','N-W']
    ax.set_xticklabels(str)
    ax.set_theta_zero_location('N') #设置零度方向北
    ax.set_theta_direction(-1) 
    plt.savefig(save_path)
    plt.show()
    

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

v=np.random.random(500)*20
plotPollutionRoseDemo(v,ws,wd,save_path='demo.png')`

demo This code is set by me using your package.

wjjxjd avatar Oct 27 '20 04:10 wjjxjd

Hi, You do a good job. How to set continuous colorbar like this? Screenshot from 2020-10-26 21-30-24

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

def plotPollutionRoseDemo(value,speed,direction,save_path='demo.png'): ''' np.random.random(500) 产生的是0~1之间的数,相当于归一化处理了 ''' fig = plt.figure() rect = [0.1, 0.1, 0.8, 0.8] hist_ax = plt.Axes(fig,rect) hist_ax.bar(np.array([1]), np.array([1])) ax=WindroseAxes.from_ax() ax.bar(direction,value,normed=True,opening=0.8,bins=[0,5,10,15,20],edgecolor='white') #ax.box(direction,speed,normed=True,opening=0.8,bins=np.arange(0, 8, 1),edgecolor='white') #wrscatter(direction,value, ax=ax, rmax=None) ax.set_legend(loc=4, bbox_to_anchor=(1., -0.07)) str=['N','N-E','E','S-E','S','S-W','W','N-W'] ax.set_xticklabels(str) ax.set_theta_zero_location('N') #设置零度方向北 ax.set_theta_direction(-1) plt.savefig(save_path) plt.show()

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

v=np.random.random(500)*20 plotPollutionRoseDemo(v,ws,wd,save_path='demo.png')` demo This code is set by me using your package.

!! Please pay special attention to your figure, with the code you provided, the chart has been rotated for 90 degree and is therefore not showing the right distribution.

wsdhrqqc avatar Nov 03 '20 03:11 wsdhrqqc

Impossible, I read the tutorials like this, may I ask which step is the problem?

wjjxjd avatar Nov 04 '20 09:11 wjjxjd

I believe something between these lines:

str=['N','N-E','E','S-E','S','S-W','W','N-W']
ax.set_xticklabels(str)
ax.set_theta_zero_location('N') #设置零度方向北
ax.set_theta_direction(-1)

I pulled in my data and it shows a 90 degree rotated, that is how i know.

wsdhrqqc avatar Nov 04 '20 21:11 wsdhrqqc

Hi, The north direction is 0, and the east direction is 90.

str=['N','N-E','E','S-E','S','S-W','W','N-W']
ax.set_xticklabels(str)
ax.set_theta_zero_location('N')
ax.set_theta_direction(-1)

My set I think is right.

This set may be direction is not right.

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

Create wind speed and direction variables

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')
ax.set_legend()
 
plt.show()

wjjxjd avatar Nov 05 '20 02:11 wjjxjd

How to set continuous colorbar like this?

That doesn't look like a continuous colorbar. Do you mean no spaces between the colored boxes?

PS: I'm closing this b/c the discussion diverged from the original question. Please open a new issue stating the original problem and commenting on my questions above.

ocefpaf avatar Sep 22 '22 12:09 ocefpaf