In [208]:
##### HW 3, problem 1 #####
# Sean Lubner

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

# import the data
ice = np.loadtxt('ice_data.txt')
agar = np.loadtxt('agar_data.txt')
water = np.loadtxt('water_data.txt')

# Generate the initial plot (figure, axes, lines)
f1, ax1 = plt.subplots()         
f1.set_size_inches(9.5,6.75)
water_line, = ax1.plot(water[:,0], water[:,1], c='k', label='H$_{2}$0 (Ref)') 
ice_line, = ax1.plot(ice[:,0], ice[:,1], label='Ice, 2 mm')  
agar_line, = ax1.plot(agar[:,0], agar[:,1], label='Agar Gel, 3 mm')  
ax1.set_title('Measured Thermal Conductivities: Water and \nAgar Gel', size=20, fontweight='bold')      
ax1.set_xlabel('Temperature, T ($^{\circ}$C)', size=18, fontweight='bold') 
ax1.set_ylabel('Thermal Conductivity, k (W/m-K)', size=18, fontweight='bold')

# Format ticks, axes & labels
ax1.axis([-30, 35, 0, 4])
ax1.set_yticks([0,1,2,3,4])
ax1.yaxis.tick_left() # remove ticks at right
ax1.xaxis.tick_bottom() # remove ticks at top
plt.setp(ax1.get_xticklabels(), fontsize=14, weight='bold')
plt.setp(ax1.get_yticklabels(), fontsize=14, weight='bold')
ax1.tick_params('both', width=2, which='major')


# Format the lines
plt.setp(agar_line, ls="none", marker='^', ms=11, mfc='lightgreen', mew=1.5, mec='green')
plt.setp(ice_line, ls="none", marker='s', ms=11, mfc='lightblue', mew=1.5, mec='blue')

# Render and format legend
l = ax1.legend([ice_line, agar_line, water_line], # control order of legend
               [ice_line.get_label(), agar_line.get_label(), water_line.get_label()], 
               bbox_to_anchor=(0.98,0.8),
               prop={'size':18}) # control location of legend
l.draw_frame(False) # no box

# Add in "a" label
plt.annotate("a", weight='bold', xy=(0.1, .9),  xycoords='axes fraction', size=42, va='center',
             bbox=dict(fc='white', ec='black', lw=2, pad=20))

plt.savefig('WaterAgarFigure_matplotlib.pdf') # Save the figure