Dec-09-2017, 09:20 PM
I have a pretty complex calculation that calls several different functions. One of them needs to loop. I think the method I have here SHOULD be working, but it keeps giving me an 'X and Y must have the same first dimension' error. Anyone see my problem?
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 def Veganuary(StartQ_A1, EndQ_A1, CurrentQ_A1, Mean_A1, Cum_impact_A1, Peak_factor_A1): Scale_A1=exp(Mean_A1) return lognorm.cdf(CurrentQ_A1, Peak_factor_A1, StartQ_A1, Scale_A1)*Cum_impact_A1 def runVeganuaryMain(x): testTime = 52 while testTime < 400: Veganuary(testTime, testTime+1, x, 0.006, 0.012, 0.55) testTime = testTime + 4 return x= np.linspace(0, 216, num=86) ax.set_title('cumulative decrease in consumption') ax.set_xlabel('$Quarter$') ax.set_ylabel('$Percent of the Population$') ax.plot(x, runVeganuaryMain(x), 'p-', lw=1, alpha=0.6, label='Major Graph
Error: runfile('C:/Users/after/OneDrive/Python Scripts/DistinctionProject2017/Figure out this veganuary bs.py', wdir='C:/Users/after/OneDrive/Python Scripts/DistinctionProject2017')

Traceback (most recent call last):
File "<ipython-input-90-e0be8571f5f4>", line 1, in <module>
runfile('C:/Users/after/OneDrive/Python Scripts/DistinctionProject2017/Figure out this veganuary bs.py', wdir='C:/Users/after/OneDrive/Python Scripts/DistinctionProject2017')
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/Python Scripts/DistinctionProject2017/Figure out this veganuary bs.py", line 44, in <module>
ax.plot(x, runVeganuaryMain(x), 'p-', lw=1, alpha=0.6, label='Major Graph')
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