Python Forum
Substituting Values in Plot - 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: Substituting Values in Plot (/thread-6217.html)



Substituting Values in Plot - Hotdog1 - Nov-11-2017

I have an equation I need to plot which generates correctly in another program but not in Python. The equation used in the other program is
syms u; %logarithmic variable
V1 =  %Equation 
xaxis = logspace(0,4); %makes logarithmic points, until 10E4
yaxis = double(subs(V1,u,xaxis)); %changes values by substituting 
(((((Not Actually in Python))))
And My Code in python is
import numpy as np
import matplotlib.pyplot as plt
plt.clf() 
w = np.linspace(0, 10E4, 10E4) 
f1=#eqn 
plt.plot(w, f1)
axes = plt.gca()
axes.set_xscale('log')
axes.set_yscale('log')
axes.set_xlim([0, 10E4])            
axes.set_ylim([0, 10E4])           
plt.show()
The problem I am having is the substitution, in the first program it does a substitution in the equation but my python program does not do so and is generating a wrong graph.


RE: Substituting Values in Plot - sparkz_alot - Nov-11-2017

Your Python code doesn't generate anything, except errors
 w = np.linspace(0, 10E4, 10E4) the third (optional) argument should be an integer, not a float. 
 f1=#eqn is not legal in Python.

Perhaps you can show us the code that actually generates a graph


RE: Substituting Values in Plot - Hotdog1 - Nov-11-2017

import numpy as np
import matplotlib.pyplot as plt
plt.clf() 
u=5;
E=1000;
w = np.linspace(0, 100000,100000) 
f1= ((w*u)/(np.sqrt(1+(((w*u)/E)**2)))) 
plt.plot(w, f1)
axes = plt.gca()
axes.set_xscale('log')
axes.set_yscale('log')
axes.set_xlim([0, 10E4])            # x-axis bounds
axes.set_ylim([0, 10E4])              # y-axis bounds
plt.show()
This is how my graph should look like:
Image Graph should look