Atkins Dynamic graph: 1B.4

1b_4_maxwell_boltzmann_1000
import math
import numpy as np
import matplotlib.pyplot as plt
import ipywidgets as widgets
from ipywidgets import FloatSlider, Layout, HBox, VBox, GridBox

px=1.0/96 #pixel in inches
xmin=0.
xmax=5.0
xgrid=1
x_ticks = np.arange(xmin,xmax+xgrid,xgrid)
show_x_ticks=False
show_x_tick_labels=False
ymin=0.
ymax=1.2
ygrid=.2
show_y_ticks=False
show_y_tick_labels=False
y_ticks = np.arange(ymin, ymax+ygrid, ygrid)
show_grid=True
npts=200
v = np.linspace(xmin, xmax, npts)
fv=np.linspace(0.0, 1.0, npts)
def mbplot(m,t):
  for x in range (0,npts):
    fv[x] = (m/t)**1.5 * v[x]**2 * math.exp(-m * v[x]**2/t)
  fig, ax = plt.subplots(figsize=(890*px,890*px/1.618))
  plt.plot(v,fv,linewidth=2,linestyle='-',color='red',clip_on=True)
  plt.axis([xmin,xmax,ymin,ymax])
  plt.ylabel(r'Distribution function, $f(v)$',fontsize='x-large')
  plt.xlabel(r'Speed, $v$',fontsize='x-large')
  ax.grid(True,color='blue',linewidth=.25)
  ax.set_xticklabels([]) #remove labels
  ax.set_yticklabels([])
  ax.set_xticks(x_ticks) #set ticks (determines grid)
  ax.set_yticks(y_ticks)
  plt.tick_params(axis='x',which='both',bottom = False, top= False) #remove ticks
  plt.tick_params(axis='y',which='both',left = False, right= False)
  plt.annotate("0",xy=(0,0),xytext=(-0.03,-0.01),xycoords='axes fraction',fontsize='x-large')
  plt.annotate("0",xy=(0,0),xytext=(-0.01,-0.05),xycoords='axes fraction',fontsize='x-large')
  plt.show

m_slider=FloatSlider(description='',min=20, max=100, step=1, value=50,continuous_update=False,
orientation='vertical',readout=False,
style=dict(handle_color='coral'),
layout=dict(height='200px',width='auto',margin='0px 0px 0px 0px'))

T_slider=FloatSlider(description='',min=10, max=100, step=1, value=50,continuous_update=False,
orientation='vertical',readout=False,
style=dict(handle_color='lightblue'),
layout=dict(height='200px',width='auto',margin='0px 0px 0px 0px'))

m_label=widgets.HTMLMath(value='<p style="font-size:medium"><i>m</i></p>',layout=dict(margin='50px 0px 0px 0px'))
T_label=widgets.HTMLMath(value='<p style="font-size:medium"><i>T</i></p>',layout=dict(margin='50px 0px 0px 0px'))

out = widgets.interactive_output(mbplot,{'m': m_slider, 't': T_slider})

GridBox(children=[HBox([VBox([m_label,m_slider],layout=Layout(align_items='center',width='40px')),
                        VBox([T_label,T_slider],layout=Layout(align_items='center',width='40px'))]),out],
        layout=Layout(
            width='1000px',
            grid_template_columns='80px 890px',
            grid_template_rows='auto',
            grid_gap='30px')
       )
 
Back to top