2

I am still getting familiar with the matplotlib library and I'm encountering a problem I've never had before. My intention is to graph the relative error associated with the scipy.integrate.quadrature method as a function of its tolerance value. What I'm encountering when I plot it, however, are two distinct lines from the same plt.plot command. How did this happen? I'll put my code in below.

from scipy import integrate

def f(x):<br/>
    return np.sqrt(1 - x**2)<br/>

xlist = []<br/>
for i in range (-12, 0):<br/>
    xlist.append(i)<br/>

tolerancelist = []<br/>
for i in xlist:<br/>
    tolerancelist.append(10**i)<br/>

ylist = []<br/>
for i in tolerancelist:<br/>
    q = integrate.quadrature(f, -1, 1, tol=i)<br/>
    ylist.append(q)<br/>
       
plt.plot(tolerancelist, ylist, label='line1')<br/>
legend = plt.legend(loc='best')
2
  • 1
    Please edit your question to include your code as text, so it is easier to copy/paste and debug. Thanks! Commented Feb 1, 2021 at 2:31
  • meta.stackoverflow.com/questions/285551/… Commented Feb 1, 2021 at 2:47

1 Answer 1

2

If you print ylist, you'll get a better understanding of what is going on.

[(1.5708027245307299, 3.9572988685954158e-07), 
(1.5708027245307299, 3.9572988685954158e-07), 
(1.5708027245307299, 3.9572988685954158e-07), 
(1.5708027245307299, 3.9572988685954158e-07), 
(1.5708027245307299, 3.9572988685954158e-07), 
(1.5708027245307299, 3.9572988685954158e-07),
(1.5708087325834776, 9.6666040283466259e-07), 
(1.5708599005218433, 8.8700570273214652e-06), 
(1.571132830068839, 8.7760917619084111e-05), 
(1.5721552241258274, 0.00062673127406376317),
(1.5759063348593505, 0.0043711928407235145), 
(1.5916172578151968, 0.041375904040254818)]

Each value in ylist is actually tuple of two values. Matplotlib is plotting both as two separate lines.

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

2 Comments

That makes a lot more sense now - thanks for figuring this out!
No problem! When in doubt, print it out

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.