Python Forum
Runtime error when trying to graph using the lognorm function (2.7)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Runtime error when trying to graph using the lognorm function (2.7)
#1

import numpy as np
from scipy.stats import lognorm
import matplotlib.pyplot as plt
from math import exp
fig, ax = plt.subplots(1, 1)

initialPop = 326300000
popGrowth = 0.007

x= np.linspace(0, 216, num=21600)
ax.set_title('cumulative changes in veganism')
ax.set_xlabel('$Quarter$')
ax.set_ylabel('$Percent of the Population$')
ax.plot(x, ((initialPop * np.exp(popGrowth * (x/4)))- lognorm.pdf(x, 0.55, 156, exp(0.05775))*0.1155 - lognorm.pdf(x, 0.55, 1, exp(0.0015))*0.003 - lognorm.pdf(x, 0.55, 80, exp(0.77))*0.154), 'p-', lw=1, alpha=0.6, label='Major Graph')
I'm having a problem where the program is graphing everything, but it's not subtracting the lognorm values like I want it to. It's just graphing I think it has to do with the data types, but I'm not sure how to fix that. Any help would be appreciated! Shy

I figured it out on my own :)
Reply
#2
It is not a trivial mathematical expression you got there.
Instead of looking at the plot I would tackle this by inspecting calculations that are done in the plot equation. Check each calculation separately to see if they give what you expect. Then combine two operations and do same, etc...
You may want to check parentheses placement also, it's hard to read this expression, and there may be some unobvious mistake. It would make much more sense to store separate calculations in variables with meaningful names.
Reply
#3
It's great you figured it, well done! Can you share with others what the issue was? :)
Reply
#4
Yes I can! It was actually working. The problem was with scale. The Lognorm function returns a percent and I forgot to multiply by the total population. Once I multiplied each value by the population it ran perfectly! (Of course until I hit the next issue). Smile
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  something that returns a linear function compatible with lognorm.pdf and lognorm.cdf? Afterdarkreader 2 3,212 Dec-19-2017, 10:42 PM
Last Post: Afterdarkreader

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020