Issue
I need to document calculations including
- the used equation and
- the variables replaced by the values used
Example: A=1, B=2
C=A+B
3=1+2
I am using Reportlab and create flowable elements with matplotlib. The following code based on the help and can achieve No.1 from the list above. Two questions arise:
How can I insert variable values in my
mathtext_demo
?Is there a way to write the general equation and the one with substituted values and result using some dictionary/solv
import matplotlib.pylab as plt mathext_demos = (r'$(\frac{5 - \frac{1}{x}}{4})$') def make_equation(code,fsize=20,imgheight=70): fig=plt.figure(figsize=(7, 0.1)) plt.annotate(code, xy=(.4, 0.1), ha='center', fontsize=fsize) plt.axis('off') make_equation(mathext_demos)
Solution
- You can use variables in your string:
a = 5
b = 4
mathext_demos = (r'$(\frac{%s - \frac{1}{x}}{%s})$' %(str(a), str(b)))
You can also use %f
for float, but I think that is something you have to figure out what works for you.
- You can write a function with the arguments
a
andb
for example en return the string. Is that what you meant with your second question?
def create_mathtext(a,b):
c = a + b
return r'${%s} = {%s} + {%s}$' % tuple(map(str, [c, a, b]))
make_equation( create_mathtext(1, 2))
Answered By - 3DspatialUser
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.