pythonplotlyhistogramvisualization

How to Change x-axis to logarithmic in PLOTLY histogram


How to make x-axis of the following histogram, logarithmic?

The following code:

data_list = [1,1,5,5,5,100,100]

import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Histogram(x=data_list, nbinsx=100))

import plotly.offline as py
py.init_notebook_mode(connected=False)
py.offline.plot(fig, filename = 'test.html')

Produces typical histogram. How can I change the x-axis logarithmic?

I also tried:

data_list = [1,1,5,5,5,100,100]

import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Histogram(x=data_list, nbinsx=100))

fig.update_layout(xaxis_type="log")
fig.update_xaxes(tick0=0, dtick=1, range=[0,2.5])

import plotly.offline as py
py.init_notebook_mode(connected=False)
py.offline.plot(fig, filename = 'test.html')

but this will result in non-logarithmic bins, and essentially, the bin at 100 disappears!


Solution

  • As said above in the comments, logarithmic axes are not possible with plotly. You could try to create bins using numpy and create a bar plot with those.