Reputation: 339
How to force Plotly to always use exponents (scientific notation)? It works for big numbers but when numbers on axis are small scientific notation become turn off.
The example below, after running this code x-axis is in scientific notation but y-axis is not.
import plotly as py
import plotly.graph_objs as go
import numpy as np
N = 1000
random_x = np.random.randn(N)*100000
random_y = np.random.randn(N)
figure = {
'data': [
go.Scatter(
x=random_x,
y=random_y,
mode='markers',
opacity=0.7,
marker={
'size': 5,
'line': {'width': 0.5, 'color': 'white'}
},
name='abc'
)
],
'layout': go.Layout(
xaxis={'title': 'x', 'showexponent': 'all', 'exponentformat': 'E', 'rangemode': 'tozero',
'ticks': 'outside'},
yaxis={'title': 'y', 'showexponent': 'all', 'exponentformat': 'E', 'rangemode': 'tozero',
'ticks': 'outside'},
hovermode='closest'
)
}
py.offline.plot(figure, filename='filename.html', auto_open=True)
Upvotes: 1
Views: 8192
Reputation: 123
I would use the 'tickformat'
option instead of 'exponantformat'
.
In your example this worked for me:
yaxis={'title': 'y', 'tickformat':'e', 'rangemode': 'tozero',
'ticks': 'outside'}
You can also specify what precision you want displayed with 'tickformat': '.2e'
Upvotes: 4