1

I am new at python. I found this code for plotting $e^x$ in $[-2,2]$:

import matplotlib.pyplot as plt
import numpy as np

100 linearly spaced numbers

x = np.linspace(-2,2,100)

the function, which is y = e^x here

y = np.exp(x)

setting the axes at the centre

fig = plt.figure() ax = fig.add_subplot(1, 1, 1) ax.spines['left'].set_position('center') ax.spines['bottom'].set_position('zero') ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') ax.xaxis.set_ticks_position('bottom') ax.yaxis.set_ticks_position('left')

plot the function

plt.plot(x,y, 'y', label='y=e^x') plt.legend(loc='upper left')

show the plot

plt.show()

How can I plot $y(x)=4e^{\frac{-118300}{x}}$ in $[3000,25000]$ in python with this code?

M.Ramana
  • 2,753

1 Answers1

1

In line $5$, you can edit the range according to your convenience. Then, in line $8$, simply editing the RHS of the equality to your desired function should suffice to give you the desired result. I hope you know the syntax to typing out the code and all the little details.

Hersh
  • 585
  • Thanks for the answer. I edited the range as x = np.linspace(3000,25000,100). But I don't know how to change $e^x$ to $4e^{\frac{-118300}{x}}$ and the syntax too. I was wondering if could you tell me about these changes. – M.Ramana Oct 22 '22 at 15:55
  • Are $y = np.exp(-118300/x)$ and $plt.plot(x,4*y, 'y', label='y=e^{-118300/x)}')$ right? – M.Ramana Oct 22 '22 at 16:02
  • That is about right except you need to add a $4 * $ at the start of $y$. – Hersh Oct 22 '22 at 16:09
  • 1
    @M.Ramana I just noticed the error regarding parenthesis in the second part. I'd suggest using $()$ and not switching to curly brackets. The corrected part would be 'y = e^(-118300/x)'. – Hersh Oct 22 '22 at 16:29
  • I got it. Thank you so much for your help. Appreciate it. – M.Ramana Oct 22 '22 at 16:47