matplotlib - To find the value on X axis corresponding to an arbitrary value of Y that doesn't contain in the list used to plot the data in python -


i have set of values redshift , have corresponding set of values deceleration parameter of universe. plot given:

enter image description here

now need value of z accurately graph q=0. have tried many commands , lead kind of errors. since not in python can't try how rectify those.

when tried command:

z1 = interp1d(z,q,0)

the result was:

scipy.interpolate.interpolate.interp1d object @ 0x051899f0

how can solve this?

my code:

while z0<zf:' '      z.append(z0)     a.append(1/(1+z0))     term=((1+(omega/(b-1)))*a[k]**(3*(b-1)))     h.append(((term-(omega/(b-1)))*h02)**0.5)     q.append(-1-((h0*term*3*(b-1)*(term-(omega/(b-1)))-0.5)/(2*h[k])))     print '%.2f \t%.4f \t%.4f \t%.15f'%(z[k],a[k],h[k],q[k])     k=k+1     z0=z0+h 

your code had issues. have python 3 here if have problem understanding ask (changed bit print , input function parts).

you did not define h02 stated equal h0. correct if wrong. here corrected code (see comments important stuff):

from pylab import* import matplotlib.pyplot plt scipy.interpolate import interp1d  fig, ax = subplots() k = 0 omega, b, h0 = 0.6911, 0.019921992722139001, 67.74 h02 = h0 + 0 # didn't specify had make z0 = 0 h = 0.05  z, a, h, q = [], [], [], [] print('value of h0, omega , beta:%.3f,%.4f,%.18f'%(h0, omega, b)) zf = float(input('enter final value of redshift:')) # remember needs output number print('red shift scale factor hubble parameter q value') # chose 10 in test. print('===========================================================')  while z0 < zf:     z.append(z0)     a.append(1/(1+z0))     term=((1+(omega/(b-1)))*a[k]**(3*(b-1)))     h.append(((term-(omega/(b-1)))*h02)**0.5)     q.append(-1-((h0*term*3*(b-1)*(term-(omega/(b-1)))-0.5)/(2*h[k])))     print('%.2f \t%.4f \t%.4f \t%.15f'%(z[k], a[k], h[k], q[k]))     k = k+1     z0 = z0+h  title('decceleration parameter(q) versus red shift(z) graph ') xlabel('redshift z') ylabel('decceleration parameter q')  z1 = interp1d(q, z) print(z1(40000)) # used redshift parameter of 10 , 0 not exist in data limits used 40 000. plot(z, q) plot([z1(40000), z1(40000)], [0, 40000], c='r') plot([0, z1(40000)], [40000, 40000], c='r')  ax.spines['left'].set_position('zero') ax.spines['right'].set_color('none') ax.yaxis.tick_left() ax.spines['bottom'].set_position('zero') ax.spines['top'].set_color('none') ax.xaxis.tick_bottom() show() 

, , results in this:

checking interception value in matplotlib plot

i added red line show result of interpolation made this:

z1 = interp1d(q, z) # create function q (input) , z (output) result = z1(40000) # checking value of z when q=40000 

the thing need remember interp1d able interpolate in region of data gave. if q within 10 , 100 cannot interpolate q=0.

i used redshift of 10 (did not know use although subject seemed interesting). not seem affect plot i'm guessing went wrong when you've put code in here or when tried understand comments (because plot different mine). make sure should , use parts can use solve problem.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -