{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline \n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from ipywidgets import interact #Librería que permite usar gráficos interactivos. " ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "def plot_function(a=0.5, color1='blue',color2='red'): #Se define una función plot, y dentro de esta se grafica. Cada parametro que queramos variar debe ser un parametro de esta funcion, y debemos asignarle algun valor inicial. Los ultimos dos parametros son los colores que tendran cada una de las curvas a graficar.\n", " A=np.linspace(-np.pi,np.pi,1000) #Dominio donde se grafica la funcion.\n", " data1=[] #Aca se guardaran los datos de la primera funcion...\n", " data2=[] #...y aca de la segunda.\n", " for j in range(len(A)):\n", " data1.append(A[j]) #Con este for vamos agregando los valores a data1, donde se usa x=A[j].\n", " for j in range(len(A)):\n", " data2.append((a/2.0)*np.sin(2.0*A[j])) #Lo mismo para data2.\n", " plt.plot(A,data1,color=color1,label=r'$\\theta$') #Se plotea data1 y se le asigna el color=color1.\n", " plt.plot(A,data2,color=color2,label=r'$\\frac{\\alpha}{2}\\sin(2\\theta)$') #Lo mismo con data2.\n", " plt.plot(0.15,0.3, 'w.',label=r'$\\alpha=$'+str(a)) #Esta linea es para mostrar el valor del parametro (en este caso a) en el mismo grafico.\n", " plt.xlabel(r'$\\theta$',fontsize=16) #Titulo eje horizontal.\n", " plt.ylabel(r'$f(\\theta)$',fontsize=16) #Titulo eje vertical.\n", " plt.xlim(-1,1) #Limites del grafico en el eje horizontal...\n", " plt.ylim(-1,1) #...y en el vertical.\n", " #plt.title(r'Ecuacion trascendente.', fontsize=16) #Titulo del grafico.\n", " plt.grid()\n", " plt.legend(prop={\"size\":12}) #Tamaño de fuente de la leyenda del grafico.\n", " plt.show()" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "fa991f7d724742f69cfbe7898282095d", "version_major": 2, "version_minor": 0 }, "text/html": [ "
Failed to display Jupyter Widget of type interactive
.
\n", " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", " that the widgets JavaScript is still loading. If this message persists, it\n", " likely means that the widgets JavaScript library is either not installed or\n", " not enabled. See the Jupyter\n", " Widgets Documentation for setup instructions.\n", "
\n", "\n", " If you're reading this message in another frontend (for example, a static\n", " rendering on GitHub or NBViewer),\n", " it may mean that your frontend doesn't currently support widgets.\n", "
\n" ], "text/plain": [ "interactive(children=(FloatSlider(value=0.5, description=u'a', max=2.0, min=0.5), Dropdown(description=u'color1', index=2, options=('red', 'yellow', 'blue', 'green'), value='blue'), Dropdown(description=u'color2', options=('red', 'yellow', 'blue', 'green'), value='red'), Output()), _dom_classes=('widget-interact',))" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "interact(plot_function, #Esta funcion invoca nuestra funcion que grafica.\n", " a=(0.5, 2.0, 0.1), #(valor minimo, valor maximo, delta a)\n", " color1=['red', 'yellow', 'blue','green'], #Lista de posibles colores para la primera curva...\n", " color2=['red', 'yellow', 'blue','green']) #...y para la segunda.\n", "None" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.14" } }, "nbformat": 4, "nbformat_minor": 2 }