Skip to content

Instantly share code, notes, and snippets.

@ThatCoolCoder
Created August 11, 2020 00:26
Show Gist options
  • Save ThatCoolCoder/bd9e26140d2bda5f1d96f201298da667 to your computer and use it in GitHub Desktop.
Save ThatCoolCoder/bd9e26140d2bda5f1d96f201298da667 to your computer and use it in GitHub Desktop.
Plot an equation (inputted as a string) on a graph. Go from start value to end value, incrementing by increment. An example equation would be 'sin(x)'
import matplotlib.pyplot as plt
from math import *
def plotEquation(equation, start=0, end=10, increment=0.1):
inputs = []
results = []
i = start
while i <= end:
inputs.append(i)
x = i
results.append(eval(equation))
i += increment
plt.plot(inputs, results)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment