0

I am currently working on a ignition curve plot, and I got stuck with creating the plot from equations that I created from sympy symbols. I keep getting an error ValueError: The arguments must be Symbols. whenever I put plot(Rho_square.subs(Y, 1.0), (T_8, 0.01, 0.1), xscale = 'log', yscale = 'log')

I tried the code below expecting to get a plot on a log scale.

from sympy import solve
import scipy.integrate as integrate
import scipy.special as special
from sympy import init_session
init_session()


q_3a = 5.09 * (10**11) * rho**2 * Y**3 * T_8**(-3) * exp(-44.027/T_8)
q_3a_wo_rho = 5.09 * (10**11) * Y**3 * T_8**(-3) * exp(-44.027/T_8)

Rho_square = (10**3) / q_3a_wo_rho

plot(Rho_square.subs(Y, 1.0), (T_8,  0.01, 0.1), xscale = 'log', yscale = 'log')

1 Answer 1

1

The problem is that your Rho_square contains huge numbers, so huge that float data type is not enough to capture the result. Also, Sympy's plot uses Matplotlib, which offers little support for very huge numbers.

So, we need to do things differently. We will use Numpy and Matplotlib directly:

from sympy import *
import matplotlib.pyplot as plt
import numpy as np
rho, Y, T_8 = symbols("rho, Y, T_8")
q_3a = 5.09 * (10**11) * rho**2 * Y**3 * T_8**(-3) * exp(-44.027/T_8)
q_3a_wo_rho = 5.09 * (10**11) * Y**3 * T_8**(-3) * exp(-44.027/T_8)
Rho_square = (10**3) / q_3a_wo_rho

# convert symbolic expression to a numerical function that
# will be evaluate by Numpy
f = lambdify(T_8, Rho_square.subs(Y, 1.0))

fig, ax = plt.subplots()
# dicretize T_8 from 0.01 to 0.1 with 100 points
# use np.longdouble, hopefully this will be enough for your case
xx = np.logspace(-2, -1, 100, dtype=np.longdouble)

# evaluate the function, and apply a log to it in order to be able
# to plot it. Essentialy, you are plotting the exponents of Rho_square.
# If you don't use log, and instead decide to use ax.loglog,
# the plot will fail because of the limited support
# to very huge numbers
yy = np.log10(f(xx))
ax.plot(xx, yy)
ax.set_xscale("log")
ax.set_xlabel(r"$T_{8}$")
ax.set_ylabel(r"$\log{\rho^{2}}$")

enter image description here

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

1 Comment

Doesn't it seem like the plotting program should autoscale? Or does it do so, but only linearly. It should scale according to the scale being used. In this case, don't scale to the average y, scale according to the average log value. If matplotlib won't do so, plot could do that.

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.