Reputation: 35
When I specify a range of y, the graph is not displayed correctly in that range.
I want to display the y-axis in the range of 10f~5u
on the log scale, but it doesn't display properly. How can I solve this problem?
# imports
import pandas as pd
import plotly.graph_objs as go
import numpy as np
# data
np.random.seed(4)
x = np.linspace(0, 1, 50)
y = np.cumsum(np.random.randn(50))
# plotly line chart
fig = go.Figure(data=go.Scatter(x=x, y=y, mode='lines'), layout_yaxis_range=[10 ** -15, 5 * 10 ** -6])
fig.update_layout(
xaxis_type="linear",
yaxis_type="log",
)
fig.show()
Upvotes: 0
Views: 59
Reputation: 1471
In the documentation for log plots, it says that
Setting the range of a logarithmic axis with plotly.graph_objects is very different than setting the range of linear axes: the range is set using the exponent rather than the actual value:
So for your example, you can remove the 10 **
when setting the range, and your range can look like [-15, 1.000011]
The output with this change produces a graph that looks like this:
For reference, the complete code looks like:
# imports
import pandas as pd
import plotly.graph_objs as go
import numpy as np
# data
np.random.seed(4)
x = np.linspace(0, 1, 50)
y = np.cumsum(np.random.randn(50))
# plotly line chart
fig = go.Figure(data=go.Scatter(x=x, y=y, mode='lines'), layout_yaxis_range=[-15, 1.000011])
fig.update_layout(
xaxis_type="linear",
yaxis_type="log",
)
fig.show()
Upvotes: 1