Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import dash
- import dash_core_components as dcc
- import dash_html_components as html
- from dash.dependencies import Input, Output
- import plotly.graph_objs as go
- import math
- app = dash.Dash(__name__)
- server = app.server
- app.title = 'resetScale2d Test'
- _config = {'modeBarButtons': [['resetScale2d']]}
- def make_fig(plot_type='linear', x=range(21), y=range(1, 211, 10)):
- xvals = list(x)
- yvals = list(y)
- xrange = [0, 50]
- yrange = [1, 500]
- if plot_type == 'log':
- yrange = [math.log10(yr) for yr in yrange]
- print(plot_type, xrange, yrange)
- traces = [go.Scatter(x=xvals, y=yvals, marker={'size': 8}, name='Tens')]
- layout = go.Layout(
- xaxis=dict(range=xrange),
- yaxis=dict(type=plot_type,
- range=yrange),
- # uirevision=plot_type
- )
- fig = go.Figure(data=traces, layout=layout)
- return fig
- app.layout = html.Div(
- [
- dcc.Dropdown(
- id='linlog',
- options=[
- {'label': 'Linear Plot', 'value': 'linear'},
- {'label': 'Log Plot', 'value': 'log'},
- ],
- value='linear',
- ),
- html.Div(
- [dcc.Graph(id='linlogplot', figure=make_fig(), config=_config)],
- style={'width': '50%', 'margin': '0 auto'},
- ),
- ]
- )
- @app.callback(Output('linlogplot', 'figure'), [Input('linlog', 'value')])
- def change_type(plot_type):
- return make_fig(plot_type=plot_type)
- if __name__ == '__main__':
- app.run_server(debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement