In [1]:
%matplotlib inline
In [6]:
import plotly.plotly as py
import numpy as np
import plotly.graph_objs as go
import plotly.offline as offline
offline.init_notebook_mode()
steps = []
magnetization = np.arange(-1.5,1.5,0.01)
temperatures = np.arange(0.1,3,0.5)
data = [dict(
visible = False,
line=dict(color='00CED1', width=6),
name = 'T = %.1f, y=tanh((m+H)/T)' % temperature,
x = magnetization,
y = np.tanh(1. / temperature * magnetization)) for temperature in temperatures]
data[0]['visible'] = True
trace = go.Scatter(
x = magnetization,
y = magnetization,
mode = 'lines',
line=dict(width=6),
name = 'y = m',
visible = True,
)
data.append(trace)
for i in range(len(data)):
step = dict(
method = 'restyle',
label = data[i]['name'].split(',')[0].split('=')[-1],
args = ['visible', [False] * len(data)],
)
step['args'][1][i] = True # Toggle i'th trace to "visible"
step['args'][1][-1] = True # Toggle the left-hand-side to always be visible
steps.append(step)
sliders = [dict(
active = len(data),
currentvalue = {"prefix": "Temperature: "},
pad = {"t": 50},
steps = steps
)]
layout = dict(sliders=sliders, legend=dict(y=0.9, x=0.))
# fig = dict(data=data, layout=layout)
fig = go.Figure(data=data, layout=layout)
offline.plot(fig, filename='../../files/ising_model_magnetization.html', show_link=False)
Out[6]:
In [ ]: