Skip to content

Instantly share code, notes, and snippets.

@erikbern
Created July 7, 2016 02:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikbern/a7c502aabb2892c3e86f9c58261d3da3 to your computer and use it in GitHub Desktop.
Save erikbern/a7c502aabb2892c3e86f9c58261d3da3 to your computer and use it in GitHub Desktop.
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