Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
import numpy
from matplotlib import pyplot
import seaborn
delta = 0.1
x = numpy.arange(0.0, 10.0, delta)
y = numpy.arange(0.0, 10.0, delta)
X, Y = numpy.meshgrid(x, y)
p = 0.5
def f(x, y):
return 0.5 * (p * x**2 + (1 - p) * y**2) / (p * x + (1 - p) * y)
Z = f(X, Y)
pyplot.figure(figsize=(10, 10))
CS = pyplot.contour(X, Y, Z, 20)
pyplot.clabel(CS, fontsize=9, inline=1)
pyplot.annotate('If $T_1=2$ and $T_2=8$,\nthen the average time waiting is %.2f min' % f(2, 8),
xy=(2, 8), color='red', size=18,
xytext=(2.5, 7.5),
arrowprops=dict(facecolor='red', shrink=0.05),
)
pyplot.axis([0, 10, 0, 10])
pyplot.xlabel('Time for train A (min)')
pyplot.ylabel('Time for train B (min)')
pyplot.title('Average time waiting for A or B')
pyplot.savefig('waiting_times_n_2.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment