Atkins Dynamic graph: 4B.2

4b_2_condition_for_phase_equilibrium_1000
import math
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import figure
from ipywidgets import interact
from ipywidgets import interact, fixed, FloatSlider, HBox, VBox, Layout, Output, Label, Box, GridspecLayout, GridBox
import ipywidgets as widgets
from matplotlib import ticker

#set up how range of plot, ticks, grid

px=1.0/96 #pixel in inches
xmin=20
xmax=90
xrange=xmax-xmin
xgrid=.1
x_ticks = np.arange(xmin,xmax+xgrid,xgrid)
show_x_ticks=False
show_x_tick_labels=False
ymin=-50
ymax=200
ygrid=2.5
show_y_ticks=False
show_y_tick_labels=False
y_ticks = np.arange(ymin, ymax+ygrid, ygrid)
show_grid=False
npts=10
x = np.linspace(xmin, xmax, npts)
y1=np.linspace(0.0, 1.0, npts)
y2=np.linspace(0.0, 1.0, npts)
def pvplot(p,s,l):
  fig = plt.figure(figsize=(790*px,790*px/1.618),dpi=96) 
  ax = fig.add_subplot(111)
  plt.axis([xmin,xmax,ymin,ymax])
  plt.plot([0,(230+p*(l-s))/4.5], [20+s*p,-0.5*(230+p*(l-s))/4.5+s*p+20], linestyle='-', lw=2,color='red')
  plt.plot([0,(230+p*(l-s))/4.5], [250+l*p,-5*(230+p*(l-s))/4.5+l*p+250], linestyle='--', lw=2,color='steelblue')
  plt.plot([(230+p*(l-s))/4.5,xmax], [-0.5*(230+p*(l-s))/4.5+s*p+20,-0.5*xmax+s*p+20], linestyle='--', lw=2,color='red')
  plt.plot([(230+p*(l-s))/4.5,xmax], [-5*(230+p*(l-s))/4.5+l*p+250,-5*xmax+l*p+250], linestyle='-', lw=2,color='steelblue')
  plt.plot([(230+p*(l-s))/4.5,(230+p*(l-s))/4.5], [ymin,-5*(230+p*(l-s))/4.5+l*p+250], linestyle='-', lw=1,color='black')
  plt.text((230+p*(l-s))/4.5,ymin-12,'$T_\mathrm{f}$',fontsize='x-large',horizontalalignment='center')
  plt.text(80,180,'solid',fontsize=14,horizontalalignment='center', color='red')
  plt.plot([65,75], [183,183], linestyle='-', lw=2,color='red')
  plt.text(80,160,'liquid',fontsize='x-large',horizontalalignment='center', color='steelblue')
  plt.plot([65,75], [165,165], linestyle='-', lw=2,color='steelblue')
  plt.ylabel(r'Chemical potential, $\mu$',fontsize='x-large')
  plt.xlabel(r'Temperature, $T$',fontsize='x-large')
  ax.xaxis.labelpad = 10
  if show_grid: plt.grid(True,color='blue',linewidth=.25)
  if not show_x_tick_labels: ax.set_xticklabels([])
  if not show_y_tick_labels: ax.set_yticklabels([])
  plt.tick_params(axis='x',which='both',bottom = show_x_ticks, top= False)
  plt.tick_params(axis='y',which='both',left = show_y_ticks, right= False)
  plt.plot((230+p*(l-s))/4.5, -5*(230+p*(l-s))/4.5+l*p+250, 'o', markersize=10, markeredgecolor='black', markerfacecolor='white', markeredgewidth=1)


  if s>l:
    plt.text(70,100,'$V_\mathrm{m}(\mathrm{s})>V_\mathrm{m}(\mathrm{l})$',horizontalalignment='center',fontsize='x-large')

  if s<l:
    plt.text(70,100,'$V_\mathrm{m}(\mathrm{s})<V_\mathrm{m}(\mathrm{l})$',horizontalalignment='center',fontsize='x-large')

  if s==l:
    plt.text(70,100,'$V_\mathrm{m}(\mathrm{s})=V_\mathrm{m}(\mathrm{l})$',horizontalalignment='center',fontsize='x-large')


  plt.show()

#margin='top right bottom left'
p=FloatSlider(description='',min=0.01, max=5, step=0.1, value=2.5,continuous_update=False,
orientation='vertical',readout=False,
style=dict(handle_color='lightcoral'),
layout=dict(height='250px',width='50px',margin='13px 0px 0px 0px',border=''))

s=FloatSlider(description='',min=0.1, max=20, step=1, value=5,continuous_update=False,
orientation='vertical',readout=False,
style=dict(handle_color='lightblue'),
layout=dict(width='50px', height='250px',margin='10px 0px 0px 0px',border=''))

l=FloatSlider(description='',min=0.1, max=20, step=1, value=15,continuous_update=False,
orientation='vertical',readout=False,
style=dict(description_width='40px',handle_color='gray'),
layout=dict(width='50px', height='250px',margin='10px 0px 0px 0px',border=''))

out = widgets.interactive_output(pvplot, {'s': s, 'l': l, 'p':p})

s_label=widgets.HTMLMath(value='<i>V</i><sub>m</sub>(s)',layout=dict(margin='0px 0px 0px 0px'))
l_label=widgets.HTMLMath(value='<i>V</i><sub>m</sub>(l)',layout=dict(margin='0px 0px 0px 0px'))
p_label=widgets.HTMLMath(value='<i>p</i>',layout=dict(margin='0px 0px 0px 0px'))
low_label=widgets.HTMLMath(value='low',layout=dict(margin='210px 0px 0px 0px'))
high_label=widgets.HTMLMath(value='high',layout=dict(margin='30px 0px 0px 0px'))

GridBox(children=[HBox([VBox([p_label,p],layout=Layout(align_items='center',width='50px')),VBox([s_label,s],layout=Layout(align_items='center',width='50px')),
                        VBox([l_label,l],layout=Layout(align_items='center',width='50px')),
                        VBox([high_label,low_label],layout=Layout(align_items='flex-start',width='30px',margin='0px 20px 0px 10px'))],
                       layout=Layout(margin='30px 0px 0px 0px')),out],
        layout=Layout(
            width='1000px',
            grid_template_columns='210px 790px',
            grid_template_rows='auto',
            grid_gap='0px 0px')
       )

Back to top