from grid_strategy import strategies
import matplotlib.pyplot as plt
import numpy as np
import ipywidgets as widgets
from ipywidgets import interact, interactive, fixed, interact_manual
import math
%matplotlib inline
print("\n\t\tBefore:")
t1 = np.arange(-5.0, 5.0, 0.2)
y0 = np.sin(t1) ** 0
y1 = np.sin(t1) ** 1
plt.subplot(2, 3, 1)
plt.plot(t1, y0)
plt.subplot(2, 3, 2)
plt.plot(t1, y1)
plt.show()
y2 = np.sin(t1) ** 2
y3 = np.sin(t1) ** 3
y4 = np.sin(t1) ** 4
plt.subplot(2, 3, 4)
plt.plot(t1, y2)
plt.subplot(2, 3, 5)
plt.plot(t1, y3)
plt.subplot(2, 3, 6)
plt.plot(t1, y4)
plt.show()
Before:
print("\n\t\tAfter: with grid-strategy")
t1 = np.arange(-5.0, 5.0, 0.2)
specs1 = strategies.SquareStrategy("left").get_grid(5)
for i, sub in enumerate(specs1):
plt.subplot(sub)
plt.plot(t1, np.sin(t1) ** i)
plt.show()
After: with grid-strategy
print("\n\tExamples of grid-strategy")
Examples of grid-strategy
print("\n\tSlider from ipywidgets for RIGHT-formatted plots (Squarify)")
t1 = np.arange(-10.0, 10.0, 0.1)
def f1(x):
specs2 = strategies.SquareStrategy("right").get_grid(x)
for i, subplot in enumerate(specs2):
plt.subplot(subplot)
plt.plot(t1, np.sin(t1) ** i)
plt.show()
interact(f1, x=widgets.IntSlider(min=1,max=15,step=1,value=5));
Slider from ipywidgets for RIGHT-formatted plots (Squarify)
interactive(children=(IntSlider(value=5, description='x', max=15, min=1), Output()), _dom_classes=('widget-int…
print("\n\tSlider from ipywidgets for LEFT-formatted plots (Squarify)")
t1 = np.arange(-10.0, 10.0, 0.1)
def f2(x):
specs3 = strategies.SquareStrategy("left").get_grid(x)
for i, subplot in enumerate(specs3):
plt.subplot(subplot)
plt.plot(t1, np.sin(t1) ** i)
plt.show()
interact(f2, x=widgets.IntSlider(min=1,max=15,step=1,value=5));
Slider from ipywidgets for LEFT-formatted plots (Squarify)
interactive(children=(IntSlider(value=5, description='x', max=15, min=1), Output()), _dom_classes=('widget-int…
print("\n\tSlider from ipywidgets for CENTER-formatted plots (Squarify)")
t1 = np.arange(-10.0, 10.0, 0.1)
def f3(x):
specs4 = strategies.SquareStrategy("center").get_grid(x)
for i, subplot in enumerate(specs4):
plt.subplot(subplot)
plt.plot(t1, np.sin(t1) ** i)
plt.show()
interact(f3, x=widgets.IntSlider(min=1,max=15,step=1,value=5));
Slider from ipywidgets for CENTER-formatted plots (Squarify)
interactive(children=(IntSlider(value=5, description='x', max=15, min=1), Output()), _dom_classes=('widget-int…
print("\n\tSlider from ipywidgets for JUSTIFIED-formatted plots (Squarify)")
t1 = np.arange(-10.0, 10.0, 0.1)
def f4(x):
specs5 = strategies.SquareStrategy("justified").get_grid(x)
for i, subplot in enumerate(specs5):
plt.subplot(subplot)
plt.plot(t1, np.sin(t1) ** i)
plt.show()
interact(f4, x=widgets.IntSlider(min=1,max=15,step=1,value=5));
Slider from ipywidgets for JUSTIFIED-formatted plots (Squarify)
interactive(children=(IntSlider(value=5, description='x', max=15, min=1), Output()), _dom_classes=('widget-int…
print("\n\tSlider from ipywidgets for rectangular plots")
t1 = np.arange(-10.0, 10.0, 0.1)
def f5(x):
specs6 = strategies.RectangularStrategy().get_grid(x)
for i, subplot in enumerate(specs6):
plt.subplot(subplot)
plt.plot(t1, np.sin(t1) ** i)
plt.show()
interact(f5, x=widgets.IntSlider(min=1,max=15,step=1,value=8));
Slider from ipywidgets for rectangular plots
interactive(children=(IntSlider(value=8, description='x', max=15, min=1), Output()), _dom_classes=('widget-int…
print("\n\tArray to store functions")
t1 = np.arange(-10.0, 10.0, .1)
funcs = [t1**3, (t1**5)/t1,t1/(2**t1),t1/(3*t1),-t1, math.sqrt(2)/t1,
5/(t1**2), -t1**13, np.sin(t1), np.tan(t1),np.cos(t1/2),
t1 + t1**9, np.tan(-np.sin(t1)), -t1**2, t1*np.arcsin(.5)]
def f6(x):
specs7 = strategies.SquareStrategy("center").get_grid(x)
for i, subplot in enumerate(specs7):
plt.subplot(subplot)
plt.xticks([])
plt.yticks([])
plt.plot(t1, funcs[i])
plt.show()
interact(f6, x=widgets.IntSlider(min=1,max=15,step=1,value=7));
Array to store functions
interactive(children=(IntSlider(value=7, description='x', max=15, min=1), Output()), _dom_classes=('widget-int…