scikit-hep / mplhep

Extended histogram plotting on top of matplotlib and HEP collaboration compatible styling
https://mplhep.readthedocs.io
MIT License
185 stars 64 forks source link

feat: added colors parameter to allow user to select the colour of ea… #447

Closed jjhw3 closed 1 year ago

jjhw3 commented 1 year ago

Added a 'colors' parameter to histplot to allow users to set histogram colours in the same way as the labels. Before this change, one could not pass one color per histogram without histplot crashing, as all the colors were being passed into ax.stairs as a _kwargs entry.

andrzejnovak commented 1 year ago

Hey @jjhw3 welcome. Could you describe the issue a bit more? I seem to easily be able to write

hs = [hist.new.Reg(10,0,10).Weight().fill(np.random.normal(3+i, 1, 1000)) for i in range(3)]
hep.histplot(hs, histtype='fill', stack=True, color=['red', 'blue', 'firebrick']);

to get the following image

jjhw3 commented 1 year ago

Hey @jjhw3 welcome. Could you describe the issue a bit more? I seem to easily be able to write

hs = [hist.new.Reg(10,0,10).Weight().fill(np.random.normal(3+i, 1, 1000)) for i in range(3)]
hep.histplot(hs, histtype='fill', stack=True, color=['red', 'blue', 'firebrick']);

to get the following image

Hey @andrzejnovak, just after creating the PR, I realised that there was an intended way to do this which was simply had unintended behaviour. While your example works, if you change the color list to a tuple of colors, it would fail. This confused me for quite a while but the fix in this PR is not the right way to do it. Please see my new PR here https://github.com/scikit-hep/mplhep/pull/448 .