14
14
DIR_DEFAULT = "direction"
15
15
FIGSIZE_DEFAULT = (8 , 8 )
16
16
DPI_DEFAULT = 80
17
- CALM_CIRCLE_COLOR = "red"
18
- CALM_CIRCLE_ALPHA = 0.4
19
17
DEFAULT_THETA_LABELS = ["E" , "N-E" , "N" , "N-W" , "W" , "S-W" , "S" , "S-E" ]
20
18
21
19
@@ -309,6 +307,20 @@ def _init_plot(self, direction, var, **kwargs):
309
307
Any argument accepted by :obj:`matplotlib.pyplot.plot`.
310
308
"""
311
309
310
+ normed = kwargs .pop ("normed" , False )
311
+ blowto = kwargs .pop ("blowto" , False )
312
+
313
+ # Calm condition, mask data if needed
314
+ calm_limit = kwargs .pop ("calm_limit" , None )
315
+ total = len (var )
316
+ if calm_limit is not None :
317
+ mask = var > calm_limit
318
+ self .calm_count = len (var ) - np .count_nonzero (mask )
319
+ if normed :
320
+ self .calm_count = self .calm_count * 100 / len (var )
321
+ var = var [mask ]
322
+ direction = direction [mask ]
323
+
312
324
# if weibull factors are entered overwrite direction and var
313
325
if "weibull_factors" in kwargs or "mean_values" in kwargs :
314
326
if "weibull_factors" in kwargs and "mean_values" in kwargs :
@@ -383,19 +395,6 @@ def _init_plot(self, direction, var, **kwargs):
383
395
# Building the angles list
384
396
angles = np .arange (0 , - 2 * np .pi , - 2 * np .pi / nsector ) + np .pi / 2
385
397
386
- normed = kwargs .pop ("normed" , False )
387
- blowto = kwargs .pop ("blowto" , False )
388
-
389
- # Calm condition
390
- calm_limit = kwargs .pop ("calm_limit" , None )
391
- if calm_limit is not None :
392
- mask = var > calm_limit
393
- self .calm_count = len (var ) - np .count_nonzero (mask )
394
- if normed :
395
- self .calm_count = self .calm_count * 100 / len (var )
396
- var = var [mask ]
397
- direction = direction [mask ]
398
-
399
398
# Set the global information dictionary
400
399
self ._info ["dir" ], self ._info ["bins" ], self ._info ["table" ] = histogram (
401
400
direction ,
@@ -404,25 +403,15 @@ def _init_plot(self, direction, var, **kwargs):
404
403
nsector ,
405
404
normed ,
406
405
blowto ,
406
+ total ,
407
407
)
408
408
409
409
return bins , nbins , nsector , colors , angles , kwargs
410
410
411
411
def _calm_circle (self ):
412
- """
413
- Draw the calm centered circle
414
- and return the initial offset for plots methods
415
- """
412
+ """Draw the calm centered circle"""
416
413
if self .calm_count and self .calm_count > 0 :
417
- circle = mpl .patches .Circle (
418
- (0.0 , 0.0 ),
419
- self .calm_count ,
420
- transform = self .transData ._b ,
421
- color = CALM_CIRCLE_COLOR ,
422
- alpha = CALM_CIRCLE_ALPHA ,
423
- )
424
- self .add_artist (circle )
425
- return self .calm_count or 0
414
+ self .set_rorigin (- (np .sqrt (self .calm_count / np .pi )))
426
415
427
416
def contour (self , direction , var , ** kwargs ):
428
417
"""
@@ -440,9 +429,9 @@ def contour(self, direction, var, **kwargs):
440
429
441
430
Other Parameters
442
431
----------------
443
- sector : integer, optional
432
+ nsector : integer, optional
444
433
number of sectors used to compute the windrose table. If not set,
445
- nsectors =16, then each sector will be 360/16=22.5°, and the
434
+ nsector =16, then each sector will be 360/16=22.5°, and the
446
435
resulting computed table will be aligned with the cardinals points.
447
436
bins : 1D array or integer, optional
448
437
number of bins, or a sequence of bins variable. If not set, bins=6,
@@ -482,10 +471,11 @@ def contour(self, direction, var, **kwargs):
482
471
),
483
472
)
484
473
485
- offset = self ._calm_circle ()
474
+ self ._calm_circle ()
475
+ origin = 0
486
476
for i in range (nbins ):
487
- val = vals [i , :] + offset
488
- offset += vals [i , :]
477
+ val = vals [i , :] + origin
478
+ origin += vals [i , :]
489
479
zorder = ZBASE + nbins - i
490
480
patch = self .plot (angles , val , color = colors [i ], zorder = zorder , ** kwargs )
491
481
self .patches_list .extend (patch )
@@ -509,7 +499,7 @@ def contourf(self, direction, var, **kwargs):
509
499
----------------
510
500
nsector: integer, optional
511
501
number of sectors used to compute the windrose table. If not set,
512
- nsectors =16, then each sector will be 360/16=22.5°, and the
502
+ nsector =16, then each sector will be 360/16=22.5°, and the
513
503
resulting computed table will be aligned with the cardinals points.
514
504
bins : 1D array or integer, optional
515
505
number of bins, or a sequence of bins variable. If not set, bins=6,
@@ -550,10 +540,11 @@ def contourf(self, direction, var, **kwargs):
550
540
),
551
541
),
552
542
)
553
- offset = self ._calm_circle ()
543
+ self ._calm_circle ()
544
+ origin = 0
554
545
for i in range (nbins ):
555
- val = vals [i , :] + offset
556
- offset += vals [i , :]
546
+ val = vals [i , :] + origin
547
+ origin += vals [i , :]
557
548
zorder = ZBASE + nbins - i
558
549
patch = self .fill (
559
550
np .append (angles , 0 ),
@@ -582,7 +573,7 @@ def bar(self, direction, var, **kwargs):
582
573
----------------
583
574
nsector : integer, optional
584
575
number of sectors used to compute the windrose table. If not set,
585
- nsectors =16, then each sector will be 360/16=22.5°, and the
576
+ nsector =16, then each sector will be 360/16=22.5°, and the
586
577
resulting computed table will be aligned with the cardinals points.
587
578
bins : 1D array or integer, optional
588
579
number of bins, or a sequence of bins variable. If not set, bins=6
@@ -624,17 +615,17 @@ def bar(self, direction, var, **kwargs):
624
615
dtheta = 2 * np .pi / nsector
625
616
opening = dtheta * opening
626
617
627
- offs = self ._calm_circle ()
618
+ self ._calm_circle ()
628
619
629
620
for j in range (nsector ):
630
- offset = offs
621
+ origin = 0
631
622
for i in range (nbins ):
632
623
if i > 0 :
633
- offset += self ._info ["table" ][i - 1 , j ]
624
+ origin += self ._info ["table" ][i - 1 , j ]
634
625
val = self ._info ["table" ][i , j ]
635
626
zorder = ZBASE + nbins - i
636
627
patch = mpl .patches .Rectangle (
637
- (angles [j ] - opening / 2 , offset ),
628
+ (angles [j ] - opening / 2 , origin ),
638
629
opening ,
639
630
val ,
640
631
facecolor = colors [i ],
@@ -663,7 +654,7 @@ def box(self, direction, var, **kwargs):
663
654
----------------
664
655
nsector: integer, optional
665
656
number of sectors used to compute the windrose table. If not set,
666
- nsectors =16, then each sector will be 360/16=22.5°, and the
657
+ nsector =16, then each sector will be 360/16=22.5°, and the
667
658
resulting computed table will be aligned with the cardinals points.
668
659
bins : 1D array or integer, optional
669
660
number of bins, or a sequence of bins variable. If not set, bins=6
@@ -698,17 +689,17 @@ def box(self, direction, var, **kwargs):
698
689
raise ValueError ("edgecolor must be a string color" )
699
690
opening = np .linspace (0.0 , np .pi / 16 , nbins )
700
691
701
- offs = self ._calm_circle ()
692
+ self ._calm_circle ()
702
693
703
694
for j in range (nsector ):
704
- offset = offs
695
+ origin = 0
705
696
for i in range (nbins ):
706
697
if i > 0 :
707
- offset += self ._info ["table" ][i - 1 , j ]
698
+ origin += self ._info ["table" ][i - 1 , j ]
708
699
val = self ._info ["table" ][i , j ]
709
700
zorder = ZBASE + nbins - i
710
701
patch = mpl .patches .Rectangle (
711
- (angles [j ] - opening [i ] / 2 , offset ),
702
+ (angles [j ] - opening [i ] / 2 , origin ),
712
703
opening [i ],
713
704
val ,
714
705
facecolor = colors [i ],
@@ -769,7 +760,7 @@ def pdf(
769
760
return (self , params )
770
761
771
762
772
- def histogram (direction , var , bins , nsector , normed = False , blowto = False ):
763
+ def histogram (direction , var , bins , nsector , normed = False , blowto = False , total = 0 ):
773
764
"""
774
765
Returns an array where, for each sector of wind
775
766
(centred on the north), we have the number of time the wind comes with a
@@ -819,7 +810,7 @@ def histogram(direction, var, bins, nsector, normed=False, blowto=False):
819
810
# and remove the last col
820
811
table = table [:, :- 1 ]
821
812
if normed :
822
- table = table * 100 / table . sum ()
813
+ table = table * 100 / total
823
814
824
815
return dir_edges , var_bins , table
825
816
0 commit comments