0

So with this code I need to plot an IV-curve exponentially decaying, but it is in wrong direction and needs to be mirrored/flipped. The x andy values are not being plotted in the correct axes and needs to be switched. It would show the relation with current exponentially decreasing while given a voltage.I tried all sorts of debugging, but it kept showing an exponential growth or the same kind of decay.

import matplotlib.pyplot as plt
import numpy as np
xdata=np.linspace(23,0)# voltage data
ydata=np.exp(xdata)# current data
plt.plot(ydata,xdata)
plt.title(r'IV-curve')
plt.xlabel('Voltage(V)')
plt.ylabel('Current(I)')
plt.show()

Here's what it looks like: https://i.sstatic.net/27Imw.jpg

Also, bear with me as this may seem like a trivial code, but I literally started coding for the first time last week, so I will get some bumps on the road :)

4
  • I just posted an answer. let me know if this is what you want Commented Aug 3, 2017 at 15:01
  • @sera I tried your code, but it says sort is not defined Commented Aug 3, 2017 at 15:06
  • I edited my code. Use ydata = np.sort(ydata) Commented Aug 3, 2017 at 15:26
  • did it work ? Let me know please when you try the new code Commented Aug 3, 2017 at 16:42

2 Answers 2

1

The problem is that the ydata that you use are not correctly ordered.

The solution is simple. Reorder the ydata.

Do this:

import matplotlib.pyplot as plt
import numpy as np

xdata = np.linspace(23,0)# voltage data
ydata = np.exp(xdata)# current data
ydata = np.sort(ydata)

plt.plot(ydata,xdata)
plt.title(r'IV-curve')
plt.xlabel('Voltage(V)')
plt.ylabel('Current(I)')

plt.show()

Result:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

It looks like maybe

plt.plot(ydata,xdata)

should be

plt.plot(xdata,ydata)

This will correct the axes. But you still aren't going to get a decaying exponential. Why? Not because of the plotting but because of your data. Your data is a growing exponential. If you want decay use something like

ydata=np.exp(-xdata)

i.e. minus sign in front of xdata.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.