I am recently exploring Plotly and I wonder if there is a way for sharing a plot and let the viewer switch between a logarithmic axis and linear axis.
Any suggestion?
Preventing the Modebar from Appearing If you would like the modebar to never be visible, then set the displayModeBar attribute in the config of your figure to false.
Syntax: For legend: fig. update_traces(showlegend=False)
Adding Traces To Subplots If a figure was created using plotly. subplots. make_subplots() , then supplying the row and col arguments to add_trace() can be used to add a trace to a particular subplot. In [12]: from plotly.subplots import make_subplots fig = make_subplots(rows=1, cols=2) fig.
The plotly. graph_objects module (typically imported as go ) contains an automatically-generated hierarchy of Python classes which represent non-leaf nodes in this figure schema. The term "graph objects" refers to instances of these classes. The primary classes defined in the plotly.
Plotly has a dropdown feature which allows the user to dynamically update the plot styling and/or the traces being displayed. Below is a minimal working example of a plot where the user can switch between a logarithmic and linear scale.
import plotly
import plotly.graph_objs as go
x = [1, 2, 3]
y = [1000, 10000, 100000]
y2 = [5000, 10000, 90000]
trace1 = go.Bar(x=x, y=y, name='trace1')
trace2 = go.Bar(x=x, y=y2, name='trace2', visible=False)
data = [trace1, trace2]
updatemenus = list([
dict(active=1,
buttons=list([
dict(label='Log Scale',
method='update',
args=[{'visible': [True, True]},
{'title': 'Log scale',
'yaxis': {'type': 'log'}}]),
dict(label='Linear Scale',
method='update',
args=[{'visible': [True, False]},
{'title': 'Linear scale',
'yaxis': {'type': 'linear'}}])
]),
)
])
layout = dict(updatemenus=updatemenus, title='Linear scale')
fig = go.Figure(data=data, layout=layout)
plotly.offline.iplot(fig)
I added two traces to the data
list to show how traces can also be added or removed from a plot. This can be controlled by the visible
list in updatemenus
for each button
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With