Skip to content

Instantly share code, notes, and snippets.

@mtourne
Created March 6, 2018 00:13
Show Gist options
  • Save mtourne/d33acd14dd169bc85a33e5073daa772f to your computer and use it in GitHub Desktop.
Save mtourne/d33acd14dd169bc85a33e5073daa772f to your computer and use it in GitHub Desktop.
graph for perfect coffee water temp
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.colors as mc
T1 = 212
# T1 is always boiling
def get_m_ratio_given_T_T2(t, t2):
if t2 - t == 0:
return 0 # return a weird value
m_ratio = (t - T1)/(t2 - t)
return m_ratio
X_inc = 5
Y_inc = 5
# x is input water temp
X_start = 30
X_end = 140
# y is resulting water temp
Y_start = 150
Y_end = 195
steps = 100
x_range = np.linspace(X_start, X_end, steps)
y_range = np.linspace(Y_start, Y_end, steps)
xv, yv = np.meshgrid(x_range, y_range, indexing='xy')
Z = np.zeros((steps, steps))
for i in range(0, steps):
for j in range(0, steps):
x = xv[i,j]
y = yv[i,j]
z = get_m_ratio_given_T_T2(y, x)
Z[i, j] = z
Z_max = np.max(Z)
print("Z_max: {}".format(Z_max))
levels1 = np.arange(0.0, 3.0, 0.1)
print(levels1)
#locator=ticker.LogLocator()
#CS = ax.contourf(x_range, y_range, Z, locator=ticker.LogLocator())
CS = plt.contourf(x_range, y_range, Z, origin=origin, levels=levels1)
#print(CS.levels)
#levels = CS.levels[::2]
#print(levels)
levels2 = [0.0, 0.10, 0.33, 0.25, 0.5, 0.66, 0.75, 1.0, 1.5, 2.0, 3.0]
CS2 = plt.contour(CS, levels=levels2, colors='r', origin=origin, vmin=0.0, vmax=1.0)
# levels2 = [0.0, 0.10, 0.33, 0.25, 0.5, 0.66, 0.75, 1.0, 1.5, 2.0, 3.0]
levels2_txt = ["0", "0.1", "1/3", "1/4", "1/2", "2/3", "3/4", "1", "1.5", "2", "3"]
fmt = {}
for l, s in zip(levels2, levels2_txt):
fmt[l] = s
plt.clabel(CS2, levels2, fmt=fmt, inline=True, fontsize=10)
plt.title('Source water is boiling')
plt.xlabel('Temp of added water')
plt.ylabel('Mixed water Temp')
#extraticks=[32, 50, 70, 90, 110, 130]
#extraticks=[]
#plt.xticks(list(plt.xticks()[0]) + extraticks)
# Make a colorbar for the ContourSet returned by the contourf call.
cbar = plt.colorbar(CS)
cbar.ax.set_ylabel('% of water to add')
# Add the contour line levels to the colorbar
#cbar.add_lines(CS2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment