#!/usr/bin/env python # coding: utf-8 # In[2]: #check if plotly is installed version #otherwise pip install plotly import plotly plotly.__version__ # In[3]: #import matplotlib import matplotlib.pyplot as plt import numpy as np get_ipython().run_line_magic('matplotlib', 'inline') # Package all mpl plotting commands inside one function def plot_mpl_fig(): # Make two time arrays t1 = np.arange(0.0, 2.0, 0.1) t2 = np.arange(0.0, 2.0, 0.01) # N.B. .plot() returns a list of lines. # The "l1, = plot" usage extracts the first element of the list # into l1 using tuple unpacking. # So, l1 is a Line2D instance, not a sequence of lines l1, = plt.plot(t2, np.exp(-t2), label='decaying exp.') l2, l3 = plt.plot(t2, np.sin(2 * np.pi * t2), '--go', t1, np.log(1 + t1), '.') l4, = plt.plot(t2, np.exp(-t2) * np.sin(2 * np.pi * t2), 'rs-.') # Add axis labels and title plt.xlabel('time') plt.ylabel('volts') plt.title('Damped oscillation') return (l1, l2, l3, l4) # return line objects (for legend, later) # Plot it! plot_mpl_fig() #assigning current matplotlib object #gcf stands for get current figure. mpl_fig1 = plt.gcf() # In[ ]: # In[12]: #converting above matplotlib into potly #communicates wit plotly server import plotly.plotly as py #plotly tools #use tls.set_credentails_file(username='yourusername' api_key='yourapikey') #use tls.get_credentials_file() to view authentication details of plotly #Refer https://plot.ly/python/user-guide/ for more infor import plotly.tools as tls #Graph objects from plotly.graph_objs import * py_fig1 = tls.mpl_to_plotly(mpl_fig1,verbose=False) #uncomment below line to view the data #py_fig1.to_string() py.iplot_mpl(mpl_fig1, strip_style=True, filename='s6_damped_oscillation') # In[ ]: