import plotly.plotly as py from plotly.graph_objs import * import numpy as np from IPython import display def r2d(a): return a*180/np.pi py.iplot([{'r': [1,2,3], 't': [0,90,270], 'type': 'bar'}], filename='polar bar circles') N = 1000 circles = 5 r = np.linspace(10, 0, N) t = np.linspace(0, r2d(2*np.pi*circles), N) py.iplot([{'r': r, 't': t}], filename='polar line circles') py.iplot({'data': [{'r': r, 't': t}], 'layout': {'direction': 'counterclockwise'}}, filename='polar line circles counterclockwise') py.iplot({'data': [{'x': r, 'y': t}]}, filename='polar line circles comp x-y') N = 50 circles = 5 r = np.linspace(10, 0, N) t = np.linspace(0, r2d(2*np.pi*circles), N) py.iplot([{'r': r, 't': t, 'mode': 'markers', 'marker': {'size': 50} }], filename='polar marker circles') py.iplot([{'x': r, 'y': t, 'mode': 'markers', 'marker': {'size': 50} }], filename='polar marker circles - comp. x-y') N = 100 circles = 5 r = np.linspace(10, 0, N) r2 = np.linspace(0,10,N) t = np.linspace(0, r2d(2*np.pi*circles), N) text = ["The angle is {:5.2f}".format(tt) for tt in t] py.iplot([{'r': r, 't': t, 'text': text, # does not work 'mode': 'lines+markers', 'line': {'color':'black'}, # bug, should color line between pts 'marker':{'color':'red', # bug, gets overwritten! 'line':{'color': 'green'} # bug, overwrites 'color':'red' } }, {'r': r2, 't': t, 'text': text, # does not work, should be supported 'mode': 'markers+text' # does not work, should be supported }], filename='polar line+marker circles') py.iplot([{'x': r[::10], # 1 out of 10 points 'y': t[::10], 'text': text, 'mode': 'lines+markers', 'line': {'color':'black'}, # colors line between pts 'marker':{'color':'red', # color the marker pts 'line':{'color': 'green'}} # colors line around marker pts }, {'x': r2[::10], 'y': t[::10], 'text': text, 'mode': 'markers+text', # coordintate in text by data pts 'textposition': 'top left' # relative position of text w.r.t. data pts }], filename='polar line+marker circles comp x-y') def c2r(x, y): return (np.sqrt(x**2+y**2), (180*np.arctan2(y,x)/np.pi)) def r2c(r, t): return (r*np.cos(np.pi*t/180), r*np.sin(np.pi*t/180)) N = 60 x = 1.4*np.random.randn(N) y = 1.4*np.random.randn(N) n = 6 r = 8 #colors = ['rgb(102,194,165)','rgb(252,141,98)','rgb(141,160,203)','rgb(231,138,195)','rgb(166,216,84)','rgb(255,217,47)'] colors = ['rgb(166,206,227)','rgb(31,120,180)','rgb(178,223,138)','rgb(51,160,44)','rgb(251,154,153)','rgb(227,26,28)'] #colors = ['rgb(27,158,119)','rgb(217,95,2)','rgb(117,112,179)','rgb(231,41,138)','rgb(102,166,30)','rgb(230,171,2)'] data = [] i = 0 for ti in range(0, 360, 360/n): i+=1 xi = x+r2c(5, ti)[0] yi = y+r2c(5, ti)[1] r = c2r(xi, yi)[0] t = c2r(xi, yi)[1] data.append({'r': r, 't': t, 'mode': 'markers', 'type': 'scatter', # bug, without it, this becomes a line plot 'name': 'Trial {i}'.format(i=i), 'marker': { 'color': colors[i-1], 'opacity': 0.7, 'line': {'color':'white', # colors line around marker pts 'width': 3}, # 'size': 20 # size of the marker pts (much smaller }}) # than in x-y graph below) layout = {'plot_bgcolor': 'rgb(223, 223, 223)', 'title': 'Hobbs-Pearson Trials', 'font': {'size': 15}, # global font size (much smaller than in x-y graph below) 'angularaxis': { 'tickcolor': 'red', # bug, color both ticks and all grid line 'ticks': 'outside', # does not work, should place angular ticks outside axis 'ticklen': 8, # does not work, should set tick length 'tickwidth': 3, # does not work, should set tick width 'gridcolor': 'green', # does not work, should color angular grid line 'gridwidth': 3 # does not work, should set angular grid line width }, 'radialaxis': { 'tickcolor': 'blue', # does not work, should color the radial axis' ticks 'ticks': 'inside', # does not work, should place radial tick inside axis 'ticklen': 16, # does not work 'tickwidth': 6, # does not work 'gridcolor': 'orange', # does not work 'gridwidth': 6 # does not work } } py.iplot({'data': data, 'layout': layout}, validate=False, filename='Hobbs-Pearson-trials') N = 60 x = 1.4*np.random.randn(N) y = 1.4*np.random.randn(N) n = 6 r = 8 #colors = ['rgb(102,194,165)','rgb(252,141,98)','rgb(141,160,203)','rgb(231,138,195)','rgb(166,216,84)','rgb(255,217,47)'] colors = ['rgb(166,206,227)','rgb(31,120,180)','rgb(178,223,138)','rgb(51,160,44)','rgb(251,154,153)','rgb(227,26,28)'] #colors = ['rgb(27,158,119)','rgb(217,95,2)','rgb(117,112,179)','rgb(231,41,138)','rgb(102,166,30)','rgb(230,171,2)'] data = [] i = 0 for ti in range(0, 360, 360/n): i+=1 xi = x+r2c(5, ti)[0] yi = y+r2c(5, ti)[1] r = c2r(xi, yi)[0] t = c2r(xi, yi)[1] data.append({'x': r, 'y': t, 'mode': 'markers', #'type': 'scatter', # not required! 'name': 'Trial {i}'.format(i=i), 'marker': { 'color': colors[i-1], 'opacity': 0.7, 'line': {'color':'white', 'width': 3}, 'size': 20 }}) layout = {'plot_bgcolor': 'rgb(223, 223, 223)', 'title': 'Hobbs-Pearson Trials', 'font': {'size': 15}, 'xaxis': { 'tickcolor': 'red', # xaxis ticks are red, 'ticks': 'outside', # placed outside the axis frame, 'ticklen': 8, # with a length of 8 pixels, 'tickwidth': 3, # and a width of 3 pixels. 'gridcolor': 'green', # vertical grid lines are green, 'gridwidth': 3 # and are 3 pixel wide }, 'yaxis': { 'tickcolor': 'blue', # yaxis ticks are blue, 'ticks': 'inside', # placed inside the axis frame, 'ticklen': 16, # with a length of 16 pixels, 'tickwidth': 6, # and a width of 6 pixles, 'gridcolor': 'orange', # horizontal grid line are orange, 'gridwidth': 6 # and are 6 pixel wide }} py.iplot({'data': data, 'layout': layout}, validate=False, filename='Hobbs-Pearson-trials comp x-y') N = 50 circles = 5 r = np.linspace(10, 0, N) t = np.linspace(0, 2*np.pi*circles, N) py.iplot({'data':[{ 'r': r, 't': t, 'mode': 'markers', }], 'layout':{ 'direction':'counterclockwise', # 'counterclockwise' should be the default 'orientation':180, # confusing name, maybe put in 'angularaxis' # maybe name it 'rotateangle' or 'plotangle' 'angularaxis': { 'range': [0,2*np.pi], # maybe have a 'type': 'radians' or 'degrees'? 'domain':[0,0.5], # not supported yet 'showline':False, # should be 'gridline' ! 'showticklabels':True, # 'tickorientation':'vertical', # maybe 'ticklabelorientation' instead # with value 'tangant', 'perpendicular' 'ticksuffix':' rad', # Nice! should be added to XAxis and YAxis 'endpadding':0, # does not appear to work. # Padding between tick and label is a good idea tough #'visible':True, # same as 'showline':False + 'showticklabels':False }, 'radialaxis': { 'range':[5,13], # adjusting the radial range 'domain': [0,0.5], # not supported yet 'orientation': 45, # bug, does not match 'direction' & 'range' 'showline': False, # should be 'gridline' ! 'showticklabels': True, # does not work 'ticksuffix':' %', # Nice! 'endpadding': 0, # does not appear to work. 'visible': True # should be 'showline' (+ 'showticklabels') ! } }}, validate=False, filename='polar add/remove line/labels') display.Image('http://www.nature.com/nrd/journal/v10/n10/images/nrd3552-f4.jpg') py.iplot({'data':[{ 't': ['A', 'B', 'C', 'A'], # does not complete the loop with string coords #'t': [0,150,270,0], # works with number coords though 'r': [1, 2, 3, 1], #'r': ['A','B','C','A'] # string radial coordinates do not work }], }, filename='radar plot?') py.iplot([ { 't': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'L', 'M', 'N'], 'r': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] }], filename='categorical line plot') py.iplot([{ 'r': [1, 2, 3], 't': [0, 180, 270], # each sector is 120 deg wide, # the sector at 270 overlays the 2 others. 'type': 'area' }], filename='categorical polar area') directions = ['North', 'N-E', 'East', 'S-E', 'South', 'S-W', 'West', 'N-W'] colors = ['rgb(242,240,247)', 'rgb(203,201,226)', 'rgb(158,154,200)', 'rgb(106,81,163)'] py.iplot({ 'data': [ { 'r': [i*100. for i in [0.775,0.725,0.7,0.45, 0.225,0.425,0.4,0.625]], 't': directions, # largest radii, must be plotted first! 'name': '11-14 m/s', 'type': 'area', 'marker': { 'color': colors[3] } }, { 'r': [i*100. for i in [ 0.575,0.5,0.45, 0.35, 0.2,0.225,0.375,0.55]], 't': directions, # second largest radii 'name': '8-11 m/s', 'type': 'area', 'marker': { 'color': colors[2] } }, { 'r': [i*100. for i in [0.4, 0.3, 0.3, 0.35, 0.075, 0.075, 0.325, 0.4]], 't': directions, # third largest radii 'name': '5-8 m/s', 'type': 'area', 'marker': { 'color': colors[1] } }, { 'r': [i*100. for i in [0.2, 0.075, 0.15, 0.225, 0.025, 0.025, 0.125, 0.225]], 't': directions, # smallest radii 'name': '< 5 m/s', 'type': 'area', 'marker': { 'color': colors[0] } } ], 'layout': { 'title': 'Wind Speed Distribution in Laurel, NE', 'font': { 'size': 10, 'family': 'Gravitas One, cursive' # should set legend font also }, 'titlefont': { 'size': 30, 'family': 'Raleway, sans-serif', # does not work }, 'radialaxis': { 'title': 'does not work', 'titlefont': { 'size': 30, 'family': 'Raleway, sans-serif', # does not work }, 'tickfont': { 'size': 30, 'family': 'Raleway, sans-serif', # does not work }, }, 'angularaxis': { 'title': 'not supported, how would this work?', 'titlefont': { 'size': 30, 'family': 'Raleway, sans-serif', # does not work }, 'tickfont': { 'size': 30, 'family': 'Raleway, sans-serif', # does not work }, }, 'legend':{ 'font': { 'size': 30, 'family': 'Raleway, sans-serif', # does not work } } }}, validate=False, filename='polar') py.iplot([ { 't': ['a', 'b', 'c'], 'r': [1, 2, 3], 'type': 'area', 'marker': { 'color': ['red', 'blue', 'green'], # does not work (same for scatter trace) 'line': { 'color':'red', # nice! 'width':5 # nice! } } } ], filename='polar fill color array') display.Image(url='http://schwehr.org/blog/attachments/2005-10/polar_test2.png') display.Image(url='http://blog.smartbear.com/wp-content/uploads/imports/favorite_pie_chart.jpg') display.Image(url='http://i.imgur.com/UQwxKEG.png') display.Image(url='http://www.nature.com/nutd/journal/v4/n2/images/nutd20146f3.jpg') display.Image(url='http://cbio.ensmp.fr/~nvaroquaux/formations/scipy-lecture-notes/_images/plot_polar_ex_1.png') display.Image('http://i.stack.imgur.com/eVTsq.jpg') display.Image(url='http://www.nature.com/nmat/journal/v12/n5/images_article/nmat3557-f4.jpg') display.Image(url='http://www.nature.com/nphoton/journal/v5/n12/images/nphoton.2011.254-f5.jpg') display.Image(url='http://www.nature.com/ng/journal/v43/n10/images_article/ng.906-F5.jpg') from IPython.display import display, HTML import urllib2 url = 'https://raw.githubusercontent.com/plotly/python-user-guide/master/custom.css' display(HTML(urllib2.urlopen(url).read()))