something that returns a linear function compatible with lognorm.pdf and lognorm.cdf? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: something that returns a linear function compatible with lognorm.pdf and lognorm.cdf? (/thread-7062.html) |
something that returns a linear function compatible with lognorm.pdf and lognorm.cdf? - Afterdarkreader - Dec-19-2017 I'm trying to figure out how to make a lognorm function compatible with a linear function. Any ideas? RE: something that returns a linear function compatible with lognorm.pdf and lognorm.cdf? - micseydel - Dec-19-2017 This doesn't seem like a generic Python question. Is it a math question? Or a question about (a) specific module(s)? RE: something that returns a linear function compatible with lognorm.pdf and lognorm.cdf? - Afterdarkreader - Dec-19-2017 It's a question about numpy and scipy. I'm using the lognorm function in scipy.stats, and I need to add a linear growth function. I was wondering if anyone knew a function I could use that would make this work. Here's my code: import numpy as np from scipy.stats import lognorm import matplotlib.pyplot as plt from math import exp def runLognormal(start, current, mean, cumImpact, peakFactor): scale = exp(mean) return lognorm.pdf(current, peakFactor, start, scale)*cumImpact def runLinear(start, stop, changePerQ, x): numIterations = (stop-start)*100 y = np.array([]) for x in range(start, stop): np.append(y, changePerQ) return y x = np.linspace(0, 212, num=21200) tax1 = runLognormal(92, x, 0.036, 0.071, 0.55) label1 = runLinear(80, 160, 0.0006875, x) ############################################### GRAPH LABEL 1 fig, lbl1 = plt.subplots(1, 1) label1X = np.linspace(80, 160, num = 8000) lbl1.set_title('Text Based Labels') lbl1.set_xlabel('Quarter') lbl1.set_ylabel('Cumulative Effect') lbl1.plot(label1X, runLinear(80, 160, 0.0006875, label1X)) ############################################################## veganGrowth = tax1 + label1 fig, ax = plt.subplots(1, 1) ax.set_title('Instantaneous Rate of Change in Population') ax.set_xlabel('$Quarter$') ax.set_ylabel('$Population Omnivores$') ax.plot(x, veganGrowth)right now neither the graph of the linear function (it's supposed to return a straight line or the ax plot is working. I'm getting a 'x and y must have the same first dimension' error for both. Error for Label graph: Error for the main graph with label graph commented out (note, in this version I took out about 50 iterations of the lognorm function, I know the problem is in the linear function because it graphs if I take that out)
|