Skip to content

Instantly share code, notes, and snippets.

@addisoneee
Created June 27, 2013 17:12
Show Gist options
  • Save addisoneee/5878325 to your computer and use it in GitHub Desktop.
Save addisoneee/5878325 to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.pyplot as plt
def fun(x):
#This is where all the info on the function goes
if x < 28:
return 100000*x - 2721000
else:
return 79000
vfun = np.vectorize(fun)
x = np.linspace(27,29)
y = vfun(x)
plt.axis([27,29,-25000,90000])
plt.plot(x,y,'-')
plt.show()
@jdhao
Copy link

jdhao commented Dec 1, 2016

numpy's piecewise method also works well for ploting
piecewise functions

@WeilongC
Copy link

WeilongC commented Oct 6, 2019

Is there anyways to avoid the vertical lines between each sections of x?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment