Ask Your Question

rhymesayers's profile - activity

2023-06-25 19:20:22 +0200 received badge  Notable Question (source)
2023-06-25 19:20:22 +0200 received badge  Popular Question (source)
2020-12-22 18:44:07 +0200 asked a question How do I put titles on subplots using matplotlib?

I am able to put titles on the subplots using Sage's plotting function, but unable to put titles on the subplots using matplotlib. Here is a simplified code of what I am working with:

import matplotlib.pyplot as mpl
#Function defining Legendre Functions of the Second Kind using Bonnet's recursion formula:
def legendre_second(n,x):
   if (n ==0):
       return log((x+1)/(x-1))/2
   elif (n==1):
       return x*legendre_second(0,x) - 1
   elif (n>1): 
       return ((2*n-1)*x*legendre_second(n-1,x) - (n-1)*legendre_second(n-2,x))/n
#Creating a plot list for the first four legendre function of the second kind:
 l = []
 p = plot(legendre_second(0,x), (x, 1,10), title = r'$Q_0$')
 l.append(p)
 p = plot(legendre_second(1,x), (x, 1,10), title = r'$Q_1$')
 l.append(p)
 p = plot(legendre_second(2,x), (x, 1,10),  title = r'$Q_2$')
 l.append(p)
 p = plot(legendre_second(3,x), (x, 1,10),  title = r'$Q_3$')
 l.append(p)

Plotting Using Sage

# Label the plots on the left column
for i in range(0,2,2):
     l[i].axes_labels(["","Value"])

# Label the plots in the last row
l[-2].axes_labels(["x interval ","Value"])
l[-1].axes_labels(["x interval ",""])

gpairs = list(zip(l[::2], l[1::2]))
pic=graphics_array(gpairs)
graphics_array(gpairs).show(frame=True,figsize=[9,7],gridlines=True)

In which I obtain subplots with titles, I would upload picture but it says I need >60 points to upload files

Now on to plotting with matplotlib

fig = mpl.figure(figsize = (15,10))
for i, g in zip(range(1, 5), pic._glist):
     subplot = mpl.subplot(2, 2, i)
     g.matplotlib(figure=fig, sub=subplot, verify=True, axes=True, frame=True,  gridlines='major')

With matplotlib I am able to obtain the subplots with the x and y axis labels, but the titles of each subplot do not transfer over to the figure created by matplotlib. How do I create titles for each individual subplot in matplotlib? Is it also possible to create an overall title for the entire figure? Thanks again for all of your guy's/girl's help. @dsejas

2020-12-22 00:15:22 +0200 received badge  Editor (source)
2020-12-21 23:07:42 +0200 answered a question help with graphics_array magic, please

@dsejas Thank you for all the work done above. But, if I wanted to add a title to each of the subplots, how would I go about doing this through matplotlib? I figured out how to do it through sage and @Juanjo 's way, but wondering if I can do it through python? Thanks again

2020-12-20 21:53:53 +0200 received badge  Scholar (source)
2020-12-15 18:48:07 +0200 commented answer How to substitute an equation into another equation to simplify it?

Thank you, this was giving me a headache! You guys are good and timely! @Juanjo, @slelievre

2020-12-15 18:45:34 +0200 received badge  Supporter (source)
2020-12-15 07:55:41 +0200 received badge  Nice Question (source)
2020-12-14 22:46:20 +0200 commented answer How to substitute an equation into another equation to simplify it?

I appreciate you taking the time to help me out, but the last line of code doesn't actually substitute B0 into A0. It would look something like this:

-(3*C*Q0d*kf*sigma0^2  + C*Q0d*kf)/(Q0d*kf) + Q0*B0

Or simplified further

B0*Q0 - C*(3*sigma0^2 + 1)

Or is there anyway to simplify (the dictionary) as a whole when it comes out of the solve function?

2020-12-14 21:45:57 +0200 received badge  Student (source)
2020-12-14 21:34:07 +0200 asked a question How to substitute an equation into another equation to simplify it?

I solved a system of equations. A solution of one of the coefficients can be plugged into another solution of a separate coefficient. How do I do this?

System of Equations

eqn1 = B0*Q0 == A0*P0 + C*(3*sigma0**2 + 1)
eqn2 = B2*Q2 == A2*P2 + 2*C
eqn3 = B0*kf*Q0d == A0*kp*P0d + 6*kp*C*sigma0
eqn4 = B2*kf*Q2d == A2*kp*P2d
sol = solve( [eqn1, eqn2, eqn3, eqn4], [B0, A0, B2, A2] )

I separated the solutions to the coefficients from the list.

sola = sol[0]
B0 = sola[0].rhs(); B0 = B0.substitute(P0d = 0)
A0 = sola[1].rhs(); A0 = A0.substitute(P0d = 0, P0 =1)
print(B0)
print(A0)

Output

6*C*kp*sigma0/(Q0d*kf)
-(3*C*Q0d*kf*sigma0^2 - 6*C*Q0*kp*sigma0 + C*Q0d*kf)/(Q0d*kf)

Now how can I substitute B0 into A0 to simplify the coefficient A0?

Thanks!

enter code here