python - Plotting a basic vectorized function -
i trying function plot vectorized function on python list interval , having name
/title
graph. new python packages numpy , matplotlib. hope can shed light on code:
import numpy np import matplotlib.pyplot plt %matplotlib inline def test_plot(x,interval,title): x = np.vectorize(x) interval = [0,interval+1] ttl = plt.title(title) plt.plot(x,interval) return plt.plot(x,interval) test_plot([-1,0,1,2,3,4],2,'test')
i error:
valueerror: x , y must have same first dimension
note: need interval
list
.
like kidjournety, don't quite understand you're wanting either, if understand comments correctly might work:
def test_plot(x, interval, title): import matplotlib.pyplot plt plt.title(title) plt.plot(x, interval) plt.show()
test_plot([1,2,3], [7,6,5], "hello, world!")
works well. if doesn't need (what vectorisation) please comment below , i'll best adjust code accordingly.
now practical reasons why original code did not work: passing list or vector 6 elements (-1 through 4) x-values of graph, 2 elements(0 , interval+1, 3 in example) y-values. poor code pair (-1, 0) , (0,3). rest of x-coordinates had no corresponding y-coordinates paired to, code failed.
Comments
Post a Comment