@@ -171,6 +171,8 @@ def histplot(
171
171
# Process input
172
172
hists = list (process_histogram_parts (H , bins ))
173
173
final_bins , xtick_labels = get_plottable_protocol_bins (hists [0 ].axes [0 ])
174
+ _bin_widths = np .diff (final_bins )
175
+ _bin_centers = final_bins [1 :] - _bin_widths / float (2 )
174
176
assert final_bins .ndim == 1 , "bins need to be 1 dimensional"
175
177
_x_axes_label = ax .get_xlabel ()
176
178
x_axes_label = (
@@ -237,8 +239,8 @@ def histplot(
237
239
final_bins ,
238
240
0 ,
239
241
[
240
- final_bins [0 ] - ( final_bins [ - 1 ] - final_bins [ 0 ] ) * 0.08 ,
241
- final_bins [0 ] - ( final_bins [ - 1 ] - final_bins [ 0 ] ) * 0.03 ,
242
+ final_bins [0 ] - _bin_widths [ 0 ] * len ( _bin_widths ) * 0.08 ,
243
+ final_bins [0 ] - _bin_widths [ 0 ] * len ( _bin_widths ) * 0.03 ,
242
244
],
243
245
)
244
246
value , variance = np .insert (value , 0 , np .nan ), np .insert (
@@ -252,8 +254,8 @@ def histplot(
252
254
flow_bins = np .append (
253
255
flow_bins ,
254
256
[
255
- final_bins [- 1 ] + ( final_bins [- 1 ] - final_bins [ 0 ] ) * 0.03 ,
256
- final_bins [- 1 ] + ( final_bins [- 1 ] - final_bins [ 0 ] ) * 0.08 ,
257
+ final_bins [- 1 ] + _bin_widths [- 1 ] * len ( _bin_widths ) * 0.03 ,
258
+ final_bins [- 1 ] + _bin_widths [- 1 ] * len ( _bin_widths ) * 0.08 ,
257
259
],
258
260
)
259
261
value , variance = np .append (value , np .nan ), np .append (variance , np .nan )
@@ -314,9 +316,6 @@ def iterable_not_string(arg):
314
316
for i in range (len (_chunked_kwargs )):
315
317
_chunked_kwargs [i ][kwarg ] = kwargs [kwarg ]
316
318
317
- _bin_widths = np .diff (final_bins )
318
- _bin_centers = final_bins [1 :] - _bin_widths / float (2 )
319
-
320
319
############################
321
320
# # yerr calculation
322
321
_yerr : np .ndarray | None
@@ -529,7 +528,7 @@ def iterable_not_string(arg):
529
528
if flow == "hint" :
530
529
ax .plot (
531
530
[
532
- final_bins [0 ] - ( final_bins [ - 3 ] - final_bins [ 2 ] ) * 0.03 ,
531
+ final_bins [0 ] - _bin_widths [ 0 ] * len ( _bin_widths ) * 0.03 ,
533
532
final_bins [0 ],
534
533
],
535
534
[0 , 0 ],
@@ -550,7 +549,7 @@ def iterable_not_string(arg):
550
549
ax .plot (
551
550
[
552
551
final_bins [- 1 ],
553
- final_bins [- 1 ] + ( final_bins [ - 3 ] - final_bins [ 2 ] ) * 0.03 ,
552
+ final_bins [- 1 ] + _bin_widths [ - 1 ] * len ( _bin_widths ) * 0.03 ,
554
553
],
555
554
[0 , 0 ],
556
555
** kwargs ,
@@ -798,7 +797,10 @@ def hist2dplot(
798
797
if any (h .values (flow = True )[0 ] > 0 ):
799
798
if flow == "hint" :
800
799
ax .plot (
801
- [xbins [0 ] - (xbins [- 3 ] - xbins [2 ]) * 0.03 , xbins [0 ]],
800
+ [
801
+ xbins [0 ] - np .diff (xbins )[0 ] * len (np .diff (xbins )) * 0.03 ,
802
+ xbins [0 ],
803
+ ],
802
804
[0 , 0 ],
803
805
transform = trans ,
804
806
** kwargs ,
@@ -809,7 +811,10 @@ def hist2dplot(
809
811
if any (h .values (flow = True )[:, 0 ] > 0 ):
810
812
if flow == "hint" :
811
813
ax .plot (
812
- [xbins [- 1 ] + (xbins [- 3 ] - xbins [2 ]) * 0.03 , xbins [- 1 ]],
814
+ [
815
+ xbins [- 1 ] + np .diff (xbins )[- 1 ] * len (np .diff (xbins )) * 0.03 ,
816
+ xbins [- 1 ],
817
+ ],
813
818
[0 , 0 ],
814
819
transform = trans ,
815
820
** kwargs ,
@@ -820,7 +825,10 @@ def hist2dplot(
820
825
if any (h .values (flow = True )[- 1 ] > 0 ):
821
826
if flow == "hint" :
822
827
ax .plot (
823
- [xbins [0 ], xbins [0 ] - (xbins [- 3 ] - xbins [2 ]) * 0.03 ],
828
+ [
829
+ xbins [0 ],
830
+ xbins [0 ] - np .diff (xbins )[0 ] * len (np .diff (xbins )) * 0.03 ,
831
+ ],
824
832
[1 , 1 ],
825
833
transform = trans ,
826
834
** kwargs ,
@@ -832,7 +840,10 @@ def hist2dplot(
832
840
if any (h .values (flow = True )[:, - 1 ] > 0 ):
833
841
if flow == "hint" :
834
842
ax .plot (
835
- [xbins [- 1 ] + (xbins [- 3 ] - xbins [2 ]) * 0.03 , xbins [- 1 ]],
843
+ [
844
+ xbins [- 1 ] + np .diff (xbins )[- 1 ] * len (np .diff (xbins )) * 0.03 ,
845
+ xbins [- 1 ],
846
+ ],
836
847
[1 , 1 ],
837
848
transform = trans ,
838
849
** kwargs ,
0 commit comments