Skip to content

Instantly share code, notes, and snippets.

@dsprenkels
Created July 28, 2017 14:52
Show Gist options
  • Save dsprenkels/e82b77ee98bbfe9699ebf2392f1e01f3 to your computer and use it in GitHub Desktop.
Save dsprenkels/e82b77ee98bbfe9699ebf2392f1e01f3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
def set_axes():
axes = plt.gca()
axes.set_xlim([-0.25,6.25])
axes.set_ylim([0,50])
return axes
def plot1():
x_poly = np.linspace(-1, 7)
y1 = 4*x_poly**2 - 25*x_poly + 42
x_points = np.arange(1, 7)
y2 = (4*x_points**2 + 25*x_points + 42) % 50
print(*zip(x_points, y2))
plt.plot(x_poly, y1, color="grey")
plt.plot([0], [42], 'ro')
plt.plot(x_points, y2, 'go')
set_axes()
fig = matplotlib.pyplot.gcf()
fig.set_size_inches(5.0, 4.0)
fig.savefig('image1.png', dpi=100)
fig.clf()
def plot2():
x_poly = np.linspace(-1, 7)
y1 = 4*x_poly**2 - 25*x_poly + 42
plt.plot(x_poly, y1, color="grey")
plt.plot([4, 1, 2], [6, 21, 8], 'go')
set_axes()
fig = matplotlib.pyplot.gcf()
fig.set_size_inches(5.0, 4.0)
fig.savefig('image2.png', dpi=100)
fig.clf()
def plot3():
x_poly = np.linspace(-1, 7)
y1 = 4*x_poly**2 - 25*x_poly + 42
plt.plot(x_poly, y1, color="grey")
plt.plot([0], [42], 'ro')
set_axes()
fig = matplotlib.pyplot.gcf()
fig.set_size_inches(5.0, 4.0)
fig.savefig('image3.png', dpi=100)
fig.clf()
plot1()
plot2()
plot3()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment