Coverage for docs/source/examples/plot_sweep1d.py: 0%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

19 statements  

1"Demonstrates manual and auto sweeping and plotting" 

2import matplotlib as mpl 

3mpl.use('Agg') 

4# comment out the lines above to show figures in a window 

5import numpy as np 

6from gpkit import Model, Variable, units 

7from gpkit.constraints.tight import Tight 

8 

9x = Variable("x", "m", "Swept Variable") 

10y = Variable("y", "m^2", "Cost") 

11m = Model(y, [ 

12 y >= (x/2)**-0.5 * units.m**2.5 + 1*units.m**2, 

13 Tight([y >= (x/2)**2]) 

14 ]) 

15 

16# arguments are: model, swept: values, posnomial for y-axis 

17sol = m.sweep({x: np.linspace(1, 3, 20)}, verbosity=0) 

18f, ax = sol.plot(y) 

19ax.set_title("Manually swept (20 points)") 

20f.show() 

21f.savefig("plot_sweep1d.png") 

22sol.save() 

23 

24# arguments are: model, swept: (min, max, optional logtol), posnomial for y-axis 

25sol = m.autosweep({x: (1, 3)}, tol=0.001, verbosity=0) 

26f, ax = sol.plot(y) 

27ax.set_title("Autoswept (7 points)\nGuaranteed to be in blue region") 

28f.show() 

29f.savefig("plot_autosweep1d.png")