how can I create graphics using matplotlib - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: how can I create graphics using matplotlib (/thread-14215.html) |
how can I create graphics using matplotlib - royer14 - Nov-20-2018 hello, I'm trying to use the matplotlib library and since I'm new my code has been written wrong, can you tell me what I failed ?, more than anything I would like to be corrected x = np.arange(1,41) b = 0.7 a =(1 - b) / (1-b**5) i = np.arange(1,5) w = a*(b**(5-i)) for n in range[5:40]: y = [w*x[n-4:n].conj().T] n = range[5:40] plt.plot(x,y) plt.show()my question from the book is the following:
[Image: fu4du3k5scs6je27g.jpg] I would appreciate any help from you RE: how can I create graphics using matplotlib - Gribouillis - Nov-20-2018 There seem to be many errors in this script, both python errors and mathematical errors. Can you describe the mathematical relation between x and y? RE: how can I create graphics using matplotlib - royer14 - Nov-20-2018 (Nov-20-2018, 01:20 PM)Gribouillis Wrote: There seem to be many errors in this script, both python errors and mathematical errors. Can you describe the mathematical relation between x and y?ok,sorry for the delay [Image: dy6u5128enq07ay7g.jpg] RE: how can I create graphics using matplotlib - Gribouillis - Nov-20-2018 It is still unclear, what are the possible values of n ? When i varies from 0 to N-1, the index n-i decreases from n to n-N+1, which may be negative. Can you explain this point?It looks like a convolution, some special functions such as numpy.convolve may be useful later once we understand what you are doing. RE: how can I create graphics using matplotlib - royer14 - Nov-20-2018 (Nov-20-2018, 05:16 PM)Gribouillis Wrote: It is still unclear, what are the possible values of Well the code had found it in Matlab and I have guided him, now I show you the code made in Matlab. vew image RE: how can I create graphics using matplotlib - Gribouillis - Nov-20-2018 I could run your code in Scilab. Here is a first python equivalent import numpy as np from matplotlib import pyplot as plt N = 40 x = np.ones(N+1) b = 0.7 S = 5 a =(1 - b) / (1-b**S) i = np.arange(1,S+1) w = a * (b**(S-i)) # print(w) y = np.zeros(N) y[S-1:] = [ np.dot(w, x[n-S+1:n+1].T) for n in range(S-1, N)] print(y) print(len(y)) plt.plot(range(S, N+1),y[S-1:], marker='o') plt.plot(range(S, N+1),y[S-1:], linestyle='-') plt.show() RE: how can I create graphics using matplotlib - royer14 - Nov-20-2018 (Nov-20-2018, 07:07 PM)Gribouillis Wrote: I could run your code in Scilab. Here is a first python equivalent fantastic, thank you very much for doing it saved me from a headache, thank you very much RE: how can I create graphics using matplotlib - royer14 - Nov-21-2018 but I want to know how you did the graph, see if I have the following, how would you do it?
RE: how can I create graphics using matplotlib - Gribouillis - Nov-21-2018 I think one only needs to replace line 4 with x = list(range(N+1))If you want to go further, you need to analyse the python code to understand how it works. |