plotly.py icon indicating copy to clipboard operation
plotly.py copied to clipboard

log_x not working in histogram

Open pjadzinsky opened this issue 5 years ago • 12 comments

Hi,

I'm new to plotly and it seems to me that following behavior is a bug.

Can someone please verify it?

Thanks for a great library.

from plotly import express as px

# this works just fine
px.histogram(np.random.randint(0, 8, 100), log_y=True, log_x=False)

# but this "works" but it produces an empty plot, no errors are raised
px.histogram(np.random.randint(0, 8, 100), log_y=False, log_x=True)

pjadzinsky avatar Nov 12 '20 23:11 pjadzinsky

It's not a bug, we just have not yet implemented histograms on log scales :)

nicolaskruchten avatar Nov 12 '20 23:11 nicolaskruchten

Thanks for the prompt reply, but the strange thing is that it works on log_y. Would also be useful if it was throwing a "NonImplementedError"

pjadzinsky avatar Nov 12 '20 23:11 pjadzinsky

That's a good idea! Should be fairly straightforward to implement in PX since the recent changes to explicitize orientation if you're up to submit a PR!

nicolaskruchten avatar Nov 12 '20 23:11 nicolaskruchten

Sure I can do that but I have no idea where to look for things. I have not looked at this repo in any way

pjadzinsky avatar Nov 13 '20 00:11 pjadzinsky

It'll be in a file called _core.py (sorry, replying from my phone, can't find full path just now ;)

nicolaskruchten avatar Nov 13 '20 00:11 nicolaskruchten

@nicolaskruchten have log scale histograms been implemented anywhere yet? if not i can add look into adding this NotImplementedError.

grisaitis avatar Apr 04 '22 19:04 grisaitis

I'm having the same problem, would be awesome to have this implemented or make it throw NotImplementedError. Thank you!

nicoszerman avatar May 18 '22 20:05 nicoszerman

For my use case, I made an implementation using numpy to build the histogram and plot it with a Bar plot customizing the ticks and hover data.

https://gist.github.com/acssantos/3108539189e60e4b059130259d21f5a9

Hope it can help circumvent the problem.

acssantos avatar May 24 '22 20:05 acssantos

So there is in fact a bug here, sorry to have misdiagnosed it earlier. Setting log_x=True causes the x-axis to become logarithmic, and when a bin edge is 0, the bars disappears. I've filed a bug in the upstream Plotly.js repo to fix this.

Note that setting log_x=True does not cause the bin edge calculation to change, so your bins will appear to be of different widths, as they do right now if you don't have a bin edge at 0.

  • Upstream issue: https://github.com/plotly/plotly.js/issues/6200

nicolaskruchten avatar May 31 '22 15:05 nicolaskruchten

Any progress?

Msx1998 avatar Nov 22 '24 13:11 Msx1998

Hi @Msx1998 - this one isn't currently on our roadmap, but we'd be happy to review a pull request from the community. Thanks - @gvwilson

gvwilson avatar Nov 22 '24 13:11 gvwilson

Is this still not implemented? I'm having the same issue.

zndr27 avatar Mar 24 '25 00:03 zndr27