Reputation: 37
I'm trying to plot a velocity profile, with the following code. The axes are plotted, however no data points are plotted.
import pandas as pd
from matplotlib import pyplot as plt
n = 0.4
k = 53
d = 0.000264
r = 0.000132
p = 15000
u = (n/n+1)*(p*1/2*k)**(1/n)*(d**((n+1)/n) - r**((n+1)/n))
plt.plot(u)
Graph produced:
Upvotes: 0
Views: 199
Reputation: 80319
First off, note that (p*1/2*k)
is a very confusing way to write a multiplication. In (about all) programming languages, the multiplications and divisions are done left to right, so, (p*1/2*k)
equals (p*k/2)
while perhaps you meant (p/(2*k))
.
When plotting a 2D graph, you have to think what you want in the x
direction, and what in the y
direction. As you only give an x
, there is nothing to plot. Also, plot
default want to draw lines and for a line at least 2 xy pairs are needed. To only draw a point, plot accepts a third parameter, for example 'ro' to represent a red dot. Supposing u
is meant to be the y
direction and you don't have an x
, you could give it a zero:
plt.plot(0, u, 'ro')
Now, probably you want to draw a curve of u
for different values of some x
. As in your equation there is no x
nor a t
, it is hard for me to know what you would like to see on the horizontal direction.
Let's suppose you want to show u
as a function of d
and that d
goes from 0.0
to 0.0005
. Typically, with numpy you create a sequence of values for d
, lets say split into 200 small intervals: d = np.linspace(0.0, 0.0005, 200)
. Then, there is the magick of numpy, that when you write u = f(d)
, numpy makes an array for u
with as many entries as d
.
Example:
import numpy as np
from matplotlib import pyplot as plt
n = 0.4
k = 53
d = np.linspace(0.0, 0.0005, 200) # 0.000264
r = 0.000132
p = 15000
u = (n / n + 1) * (p * 1 / 2 * k) ** (1 / n) * (d ** ((n + 1) / n) - r ** ((n + 1) / n))
plt.plot(d, u)
plt.show()
Upvotes: 1