from IPython.display import Image Image(url = 'https://i.imgur.com/4DrMgLI.png') %matplotlib inline import matplotlib.pyplot as plt # side-stepping mpl backend import matplotlib.gridspec as gridspec # subplots import numpy as np import plotly.plotly as py import plotly.tools as tls from plotly.graph_objs import * py.sign_in("IPython.Demo", "1fw3zw2o13") import plotly plotly.__version__ fig1 = plt.figure() import matplotlib.pyplot as plt import numpy as np import matplotlib.mlab as mlab mean = [10,12,16,22,25] variance = [3,6,8,10,12] x = np.linspace(0,40,1000) for i in range(4): sigma = np.sqrt(variance[i]) y = mlab.normpdf(x,mean[i],sigma) plt.plot(x,y, label=r'$v_{}$'.format(i+1)) plt.xlabel("X") plt.ylabel("P(X)") py.iplot_mpl(fig1, strip_style = True) from IPython.display import Image Image(url = 'http://i.imgur.com/PkRRmHq.png') library(WDI) library(ggplot2) #Grab GNI per capita data for Chile, Hungary and Uruguay dat = WDI(indicator='NY.GNP.PCAP.CD', country=c('CL','HU','UY'), start=1960, end=2012) #a quick plot with legend, title and label wb <- ggplot(dat, aes(year, NY.GNP.PCAP.CD, color=country)) + geom_line() + xlab('Year') + ylab('GDI per capita (Atlas Method USD)') + labs(title <- "GNI Per Capita ($USD Atlas Method)") py$ggplotly(wb) tls.embed('RgraphingAPI', '1457') fig = py.get_figure('RgraphingAPI', '1457') fig.strip_style() py.iplot(fig) my_data = py.get_figure('PythonAPI', '455').get_data() %matplotlib inline import matplotlib.pyplot as plt fig1 = plt.figure() plt.subplot(311) plt.plot(my_data[0]['x'], my_data[0]['y']) plt.subplot(312) plt.plot(my_data[1]['x'], my_data[1]['y']) plt.subplot(313) plt.plot(my_data[2]['x'], my_data[2]['y']) py.iplot_mpl(fig1, strip_style = True) my_data[1]['yaxis'] = 'y2' my_data[2]['yaxis'] = 'y3' layout = Layout( yaxis=YAxis( domain=[0, 0.33] ), legend=Legend( traceorder='reversed' ), yaxis2=YAxis( domain=[0.33, 0.66] ), yaxis3=YAxis( domain=[0.66, 1] ) ) fig = Figure(data=my_data, layout=layout) py.iplot(fig) Image(url = 'http://i.imgur.com/rHP53Oz.png') tls.embed('MattSundquist', '1404') tls.embed('MattSundquist', '1339') Image(url = 'http://i.imgur.com/JJkNPJg.png') ggplot = py.get_figure('MattSundquist', '1339') ggplot #print it ggplot_data = ggplot.get_data() ggplot_data import pandas as pd my_data = py.get_figure('MattSundquist', '1339').get_data() frames = {data['name']: {'x': data['x'], 'y': data['y']} for data in my_data['data']} df = pd.DataFrame(frames) df from plotly.graph_objs import Data, Layout, Figure help(Figure) Image(url = 'http://i.imgur.com/bGj8EzI.png?1') %%matlab close all % Create a set of values for the damping factor zeta = [0.01 .02 0.05 0.1 .2 .5 1 ]; % Define a color for each damping factor colors = ['r' 'g' 'b' 'c' 'm' 'y' 'k']; % Create a range of frequency values equally spaced logarithmically w = logspace(-1, 1, 1000); % Plot the gain vs. frequency for each of the seven damping factors figure; for i = 1:7 a = w.^2 - 1; b = 2*w*zeta(i); gain = sqrt(1./(a.^2 + b.^2)); loglog(w, gain, 'color', colors(i), 'linewidth', 2); hold on; end % Set the axis limits axis([0.1 10 0.01 100]); % Add a title and axis labels title('Gain vs Frequency'); xlabel('Frequency'); ylabel('Gain'); % Turn the grid on grid on; % ---------------------------------------- % Let's convert the figure to plotly structures, and set stripping to false [data, layout] = convertFigure(get(gcf), false); % But, before we publish, let's modify and add some features: % Naming the traces for i=1:numel(data) data{i}.name = ['$\\zeta = ' num2str(zeta(i)) '$']; %LATEX FORMATTING data{i}.showlegend = true; end % Adding a nice the legend legendstyle = struct( ... 'x' , 0.15, ... 'y' , 0.9, ... 'bgcolor' , '#E2E2E2', ... 'bordercolor' , '#FFFFFF', ... 'borderwidth' , 2, ... 'traceorder' , 'normal' ... ); layout.legend = legendstyle; layout.showlegend = true; % Setting the hover mode layout.hovermode = 'closest'; % Giving the plot a custom name plot_name = 'My_improved_plot'; % Sending to Plotly response = plotly(data, struct('layout', layout, ... 'filename',plot_name, ... 'fileopt', 'overwrite')); display(response.url) tls.embed('MATLAB-Demos', '4') Image(url = 'https://i.imgur.com/sAHsjk3.png') Image (url = 'https://i.imgur.com/y4t5hdj.png') Image (url = 'http://i.imgur.com/BUOe85E.png') tls.embed('MattSundquist', '1337') Image(url = 'http://i.imgur.com/YRyTCQy.png') Image (url = 'http://i.imgur.com/ATn7vE4.png') Image(url = 'http://i.imgur.com/QaIw9p4.png?1') Image(url = 'http://i.imgur.com/OqXKs0r.png') from IPython.display import HTML i = """
<iframe src="https://plot.ly/~MattSundquist/1334/650/550" width="650" height=550" frameBorder="0" seamless="seamless" scrolling="no"></iframe>
""" h = HTML(i); h HTML('

') Image(url='https://i.imgur.com/gUC4ajR.png') HTML('
') tls.embed('flann321', '9') tls.embed('streaming-demos','4') HTML('
') # CSS styling within IPython notebook from IPython.core.display import HTML import urllib2 def css_styling(): url = 'https://raw.githubusercontent.com/plotly/python-user-guide/master/custom.css' styles = urllib2.urlopen(url).read() return HTML(styles) css_styling()