Skip to content

[BUG] Binning misalignment using plot_ratio with Int axes #637

@GuillermoFidalgo

Description

@GuillermoFidalgo

Describe the bug

I have two histograms with the same axes ( a dataset axis that is StrCategory, a channel axes that is also StrCategory and an Njet axis defined as)

njet_axis = hist.axis.Integer(4,15, name = 'njet', label='Jet multiplicity')

All is well and good most of the time with other axes but when trying to make a ratio plot for something like Data/MC with Interger axes it is not aligning the ratio plot points correctly with the bins on the regular plot above it. I don't understand why it's apparently not aligning the ratios on the lower axes as I would expect.

Steps to reproduce

A MWE is given below.
Running code below shows that the issues seems to be related with Int axes

import hist
import matplotlib.pyplot as plt

d = [1,
     2,2,
     3,3,3,
     4,4,4,4,
     5,5,5,5,5]*10_000

d2 = [1,1,1,1,1,
      2,2,2,2,
      3,3,3,
      4,4,
      5]*10_000

temp_H_Int = hist.new.Int(1,6,name= 'Int').Double().fill(d)
temp_H2_Int = hist.new.Int(1,6,name= 'Int').Double().fill(d2)

temp_H_Var = hist.new.Var([1,2,3,4,5,6],name= 'Var').Double().fill(d)
temp_H2_Var = hist.new.Var([1,2,3,4,5,6],name= 'Var').Double().fill(d2)

# Compare the plots (These are seen to be identical, as expected)
fig,ax = plt.subplots(1,2,figsize = [15,5])
temp_H_Int.plot(ax=ax[0])
temp_H2_Int.plot(ax=ax[0])


temp_H_Var.plot(ax=ax[1])
temp_H2_Var.plot(ax=ax[1])
plt.show()
Image

Now look at the ratio plots code in 2 different cells

# Ratio Plots appear to be aligned differently with the bins wrt previous plots
temp_H_Int.plot_ratio(temp_H2_Int,
                      rp_num_label="H Int",
                      rp_denom_label="H2 Int",
                      rp_ylabel='H/H2',
                      rp_uncert_draw_type="line")
# This one produces the expected alignment 
temp_H_Var.plot_ratio(temp_H2_Var,
                      rp_num_label="H Var",
                      rp_denom_label="H2 Var",
                      rp_ylabel='H/H2',
                      rp_uncert_draw_type="line")
Image Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions