ammonium,

Here you go, you’ll need numpy, scipy and matplotlib:


<span style="color:#323232;">from scipy.optimize import curve_fit
</span><span style="color:#323232;">from matplotlib import pyplot as plt
</span><span style="color:#323232;">
</span><span style="color:#323232;"># 2010-2013 data from https://ourworldindata.org/renewable-energy [TWh]
</span><span style="color:#323232;">y = np.array([32, 63, 97, 132, 198, 256, 328, 445, 575, 659, 853, 1055, 1323, 1629])
</span><span style="color:#323232;">x = np.arange(0, len(y))
</span><span style="color:#323232;">
</span><span style="color:#323232;"># function we expect the data to fit
</span><span style="color:#323232;">fit_func = lambda x, a, b, c: a * np.exp2(b * x ) + c
</span><span style="color:#323232;">popt, _ = curve_fit(fit_func, x, y, maxfev=5000)
</span><span style="color:#323232;">
</span><span style="color:#323232;">fig, ax = plt.subplots()
</span><span style="color:#323232;">ax.scatter(x + 2010, y, label="Data", color="b", linestyle=":")
</span><span style="color:#323232;">ax.plot(x + 2010, fit_func(x, *popt), color="r", linewidth=3.0, linestyle="-", label='best fit curve: $y={0:.3f} * 2^{{{1:.3f}x}} + {2:.3f}$'.format(*popt))
</span><span style="color:#323232;">plt.legend()
</span><span style="color:#323232;">plt.show()
</span>

Here’s what I get, global solar energy generated doubles every ~3.5 (1/0.284) years.

https://lemmy.world/pictrs/image/5999087a-772f-4cb2-81fa-98f7684bd2a6.png

  • All
  • Subscribed
  • Moderated
  • Favorites
  • world@lemmy.world
  • fightinggames
  • All magazines