plotly / plotly.py

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!
https://plotly.com/python/
MIT License
15.8k stars 2.52k forks source link

problem with log_x not working in histogram #2899

Open pjadzinsky opened 3 years ago

pjadzinsky commented 3 years ago

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)
nicolaskruchten commented 3 years ago

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

pjadzinsky commented 3 years ago

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"

nicolaskruchten commented 3 years ago

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!

pjadzinsky commented 3 years ago

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

nicolaskruchten commented 3 years ago

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

grisaitis commented 2 years ago

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

nicoszerman commented 2 years ago

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

acssantos commented 2 years ago

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.

nicolaskruchten commented 2 years ago

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.