'log' parameter is not working in hl.plot.histogram()

Hi Hail team,

I am trying to get a histogram with log scale in Y-axis using the code as below.

hist=hl.plot.histogram(mt.variant_qc.call_rate, bins = 50, legend='call-rate',title='variant level call-rate distribution',log=True)

When I ran the code without a ‘log’ parameter, it worked well. But after adding a ‘log’ parameter, it gave me an error like this.

    421     if log:
--> 422         data.bin_freq = [math.log10(x) for x in data.bin_freq]
    423         data.n_larger = math.log10(data.n_larger)
    424         data.n_smaller = math.log10(data.n_smaller)

/opt/conda/miniconda3/lib/python3.8/site-packages/hail/utils/struct.py in __setattr__(self, key, value)
     63     def __setattr__(self, key, value):
     64         if key in self._fields:
---> 65             raise ValueError("Structs are immutable, cannot overwrite a field.")
     66         else:
     67             super().__setattr__(key, value)

ValueError: Structs are immutable, cannot overwrite a field.

Please let me know how to solve it. Thank you.


Hey Jina,

Sorry we missed this. This isn’t your fault, it seems that option is just broken. I’ll look into it.

I have a PR to fix this problem: [query] Fix old hl.plot.histogram log argument by johnc1231 · Pull Request #11268 · hail-is/hail · GitHub

In the meantime, if you’re familiar with ggplot, we’ve recently added a new ggplot like interface to hail. So you could get your plot by doing:

from hail.ggplot import *
rows = mt.rows()
hist = ggplot(rows, aes(x=rows.variant_qc.call_rate)) + geom_histogram(min_val = 0, max_val=1, bins=50) + scale_y_log10()

Thank you for your support. Your code could be a good alternative.


Hey Jina,

As of hail release 0.2.83 (released yesterday), your original usage of hl.plot.histogram should work as well.

Thanks a lot.