Dec-20-2017, 02:26 AM
They're the same code, but here's the error code for the abbreviated version I'm using to debug (it's the exact same code, just minus repeated functions that I know work fine).
First error
First error
Error:Traceback (most recent call last):
File "<ipython-input-1-1ea6155a3286>", line 1, in <module>
runfile('C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction/Linear function.py', wdir='C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction')
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 685, in runfile
execfile(filename, namespace)
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 71, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
File "C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction/Linear function.py", line 37, in <module>
lbl1.plot(label1X, runLinear(80, 160, 0.0006875, label1X))
File "C:\Python27\lib\site-packages\matplotlib\axes\_axes.py", line 1373, in plot
for line in self._get_lines(*args, **kwargs):
File "C:\Python27\lib\site-packages\matplotlib\axes\_base.py", line 304, in _grab_next_args
for seg in self._plot_args(remaining, kwargs):
File "C:\Python27\lib\site-packages\matplotlib\axes\_base.py", line 282, in _plot_args
x, y = self._xy_from_xy(x, y)
File "C:\Python27\lib\site-packages\matplotlib\axes\_base.py", line 223, in _xy_from_xy
raise ValueError("x and y must have same first dimension")
ValueError: x and y must have same first dimension
Second error (with the lbl1 print commented outError:runfile('C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction/Linear function.py', wdir='C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction')
Traceback (most recent call last):
File "<ipython-input-2-1ea6155a3286>", line 1, in <module>
runfile('C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction/Linear function.py', wdir='C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction')
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 685, in runfile
execfile(filename, namespace)
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 71, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
File "C:/Users/after/OneDrive/Distinction Project Files 2017/Python Scripts for Distinction/Distinction/Linear function.py", line 40, in <module>
veganGrowth = tax1 + label1
ValueError: operands could not be broadcast together with shapes (21200,) (0,)
Here's the 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): y = np.array([]) time = start while time <= stop: np.append(y, changePerQ) time = time + 0.01 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)