# Get this figure: fig = py.get_figure("https://chart-studio.plotly.com/~messier51/32/")
# Get this figure's data: data = py.get_figure("https://chart-studio.plotly.com/~messier51/32/").get_data()
# Add data to this figure: py.plot(Data([Scatter(x=[1, 2], y=[2, 3])]), filename ="Ratings Histograms", fileopt="extend")
# Get x data of first trace: x1 = py.get_figure("https://chart-studio.plotly.com/~messier51/32/").get_data()[0]["x"]

# Get figure documentation: https://chart-studio.plotly.com/python/get-requests/
# Add data documentation: https://chart-studio.plotly.com/python/file-options/

# If you're using unicode in your file, you may need to specify the encoding.
# You can reproduce this figure in Python with the following code!

# Learn about API authentication here: https://chart-studio.plotly.com/python/getting-started
# Find your api_key here: https://chart-studio.plotly.com/settings/api

import plotly.plotly as py
from plotly.graph_objs import *
py.sign_in('username', 'api_key')
trace1 = {
  "uid": "d7e089", 
  "name": "IMDB (1-10 rating)", 
  "type": "histogram", 
  "x": ["Col3", 8.7, 7.4, 8.7, 8.7, 8.8, 8.8, 9.3, 8.8, 8.2, 8.9, 7.7, 8, 9.2, 9.4, 8.5, 8.7, 9.1, 8.9, 9.1, 8.2, 8.6, 8.4, 9.2, 8.5, 7.3, 8.7, 8.6, 8.3, 5.9, 8.4, 8.5, 9.1, 8.9, 7.1, 8.8, 8.5, 9.6, 8.2, 8.5, 8.5, 8.7, 8.3, 8.8, 8.9, 6.5, 8.9, 8.6, 8.7, 8.1, 9, 9.1, 8.1, 8.5, 9.3, 9.4, 8.4, 8.6, 8.7, 8.3, 7.9, 8.9, 8.1, 8.4, 8.3, 9.5, 9.3, 8.8, 7.5, 8.9, 8.7, 9.1, 7.8, 8.6, 8.9, 8.7, 7.4, 9.1, 8.9, 8.1, 8.4, 9.1, 8.5, 8.6, 7.8, 8.7, 9, 8.9, 8.1, 8.1, 8.6, 8.7, 8.9, 8.8, 8.9, 9, 8.5, 9.2, 9.4, 8.8, 8.8, 8.8, 8.5, 9.4, 9, 8.8, 9.5, 8.7, 8.5, 8.6, 8, 9.3, 8.7, 7.5, 7.7, 9.1, 8.5, 8.4, 8.7, 8.6, 8.9, 9, 8.7, 9.4, 8.4, 9, 8.4, 9.3, 8.7, 9.2, 8.4, 8.5, 7.4, 7.3, 8.6, 8.3, 8.8, 8.5, 8.3, 9, 8.9, 8.7, 8.2, 9.1, 7.7, 8.4, 9.1, 8.9, 7.9, 7.5, 9.3, 8.9, 8.7, 8.8, 8, 8.7, 8.7, 7.7, 8.3, 8.6, 8.5, 8.5, 8.8, 7.9, 8.8, 8.6, 8.2, 8.8, 9, 9.7, 8.4, 8.9, 9.1, 8.7, 8.4, 9.1, 8.8, 8.8, 9.2, 9, 9.6, 8.3, 9.1, 8.8, 8.2, 8.8, 8.8, 9, 9.1, 8.3, 9.3, 7.9, 9, 8.9, 8.4, 9, 8.2, 8.6, 8.4, 8.8, 9, 8.7, 7.9, 8.9, 8.6, 8.5, 8.7, 9.3, 8.1, 8.2, 8.6, 9.1, 8.1, 9.4, 8.6, 8.8, 8.8, 9.2, 8.7, 7.7, 8.5, 8.6, 8.2, 8.1, 7.8, 8.1, 7.9, 8.1, 7.6, 7.8, 7.7, 8.1, 7.8, 7.7, 7.8, 8.2, 7.9, 7.5, 7.7, 7.8, 8.4, 7.4], 
  "xbins": {
    "end": 9.8, 
    "size": 0.2, 
    "start": 5.8
  }, 
  "marker": {
    "line": {
      "color": "#444", 
      "width": 2
    }, 
    "color": "rgba(31, 119, 180, 0.5)"
  }, 
  "nbinsx": 0, 
  "error_y": {"visible": False}, 
  "opacity": 1, 
  "autobinx": True, 
  "autobiny": True, 
  "histnorm": "percent"
}
trace2 = {
  "name": "Nielsen (millions of viewers)", 
  "type": "histogram", 
  "x": ["nielsen_viewers", "5.69", "5.01", "5.01", "5.40", "5.50", "5.00", "5.08", "4.47", "4.21", "5.38", "4.23", "3.86", "5.82[27]", "4.27[28]", "3.96[29]", "4.22[30]", "3.76[31]", "3.67[32]", "3.62[33]", "3.99[34]", "3.26[35]", "3.99[36]", "3.93[37]", "3.34[38]", "3.78[39]", "3.29[40]", "3.65[41]", "3.38[42]", "3.19[43]", "3.16[44]", "3.12[45]", "3.24[46]", "3.44[47]", "3.42[48]", "3.37[49]", "2.84[50]", "3.03[51]", "3.52[52]", "3.38[53]", "3.25[54]", "3.33[55]", "3.11[56]", "2.90[57]", "2.72[58]", "2.97[59]", "3.16[59]", "3.03[59]", "3.02[59][note 3]", "3.24[59]", "3.01[59]", "2.88[59]", "3.02[59]", "2.95[59]", "2.68[59]", "2.97[59]", "3.23[59]", "2.22[59]", "2.63[59]", "2.55[59]", "3.00[59]", "3.96[60]", "3.18[61]", "3.51[62]", "3.15[63]", "3.06[64]", "3.25[65]", "3.55[66]", "3.24[67]", "2.94[68]", "3.34[69]", "2.98[70]", "3.06[71]", "3.56[72]", "3.37[73]", "2.84[74]", "3.37[75]", "3.13[76]", "3.27[77]", "2.70[78]", "2.95[79]", "2.79[80]", "2.89[81]", "3.40[82]", "2.80[83]", "2.66[84]", "2.62[85]", "2.47[86]", "2.59[87]", "2.90[88]", "2.65[89]", "2.69[90]", "2.51[91]", "2.79[92]", "2.65[93]", "2.28[94]", "2.51[95]", "2.95[96]", "2.40[97]", "2.78[98]", "2.45[99]", "2.82[100]", "2.38[101]", "2.53[102]", "2.84[103]", "2.90[104]", "2.33[105]", "2.16[106]", "2.84[107]", "2.47[108]", "2.52[109]", "2.46[110]", "2.09[111]", "1.94[112]", "2.15[113]", "2.27[114]", "2.25[115]", "1.97[116]", "2.25[117]", "2.18[118]", "2.14[119]", "2.26[120]", "1.90[121]", "2.01[122]", "2.11[123]", "2.02[124]", "2.11[124]", "2.01[125]", "1.80[126]", "1.72[127]", "1.69[128]", "1.92[129]", "1.74[130]", "1.84[131]", "1.85[132]", "1.55[133]", "1.89[134]", "1.82[135]", "1.55[136]", "1.72[137]", "1.88[138]", "1.74[139]", "1.73[140]", "1.63[141]", "1.78[142]", "1.57[143]", "1.61[144]", "1.66[145]", "1.58[146]", "1.56[147]", "1.85[148]", "2.51[149]", "2.13[150]", "1.86[151]", "1.78[152]", "2.32[153]", "2.32[154]", "2.00[155]", "2.06[156]", "1.99[157]", "2.01[158]", "2.12[159]", "2.29[160]", "2.41[161]", "2.10[162]", "2.13[163]", "2.16[164]", "2.23[165]", "1.90[166]", "2.38[167]", "2.07[168]", "2.07[169]", "2.31[170]", "2.59[171]", "2.33[172]", "2.34[173]", "2.19[174]", "2.15[175]", "2.36[176]", "2.01[177]", "2.39[178]", "2.42[179]", "2.21[180]", "2.65[181]", "2.76[182]", "2.46[183]", "2.12[184]", "1.93[185]", "1.86[186]", "2.25[187]", "1.60[188]", "2.10[189]", "2.03[190]", "1.59[191]", "1.74[192]", "2.30[193]", "2.50[194]", "2.13[195]", "2.08[196]", "1.93[197]", "2.17[198]", "2.54[199]", "2.30[200]", "2.33[201]", "2.62[202]", "2.42[203]", "2.06[204]", "2.21[205]", "1.98[206]", "2.09[207]", "1.73[208]", "1.70[209]", "1.70[210]", "1.76[211]", "1.63[212]", "1.74[213]", "1.45[214]"], 
  "xbins": {
    "end": 5.8, 
    "size": 0.2, 
    "start": 3.8
  }, 
  "marker": {
    "line": {"width": 3}, 
    "color": "rgba(249, 203, 156, 0.59)"
  }, 
  "nbinsx": 12, 
  "histnorm": "percent"
}
data = Data([trace1, trace2])
layout = {
  "font": {
    "size": 12, 
    "color": "#444", 
    "family": "\"Open sans\", verdana, arial, sans-serif"
  }, 
  "title": "Ratings Histograms", 
  "width": 730, 
  "xaxis": {
    "type": "linear", 
    "dtick": 1, 
    "range": [3.8000000000000003, 9.799999999999995], 
    "tick0": 0, 
    "ticks": "", 
    "mirror": False, 
    "nticks": 0, 
    "ticklen": 6, 
    "autotick": True, 
    "showgrid": False, 
    "showline": False, 
    "tickfont": {
      "size": 12, 
      "color": "#444", 
      "family": "\"Open sans\", verdana, arial, sans-serif"
    }, 
    "zeroline": False, 
    "autorange": True, 
    "gridcolor": "white", 
    "gridwidth": 1, 
    "linecolor": "rgba(152, 0, 0, 0.5)", 
    "linewidth": 1.5, 
    "rangemode": "normal", 
    "tickangle": "auto", 
    "tickcolor": "rgba(0, 0, 0, 0)", 
    "titlefont": {
      "size": 14, 
      "color": "#444", 
      "family": "\"Open sans\", verdana, arial, sans-serif"
    }, 
    "showexponent": "all", 
    "zerolinewidth": 1, 
    "exponentformat": "B", 
    "showticklabels": True
  }, 
  "yaxis": {
    "type": "linear", 
    "dtick": 1, 
    "range": [0, 35.08771929824562], 
    "tick0": 0, 
    "ticks": "", 
    "title": "percentage", 
    "mirror": False, 
    "nticks": 0, 
    "ticklen": 6, 
    "autotick": True, 
    "showgrid": True, 
    "showline": False, 
    "tickfont": {
      "size": 12, 
      "color": "#444", 
      "family": "\"Open sans\", verdana, arial, sans-serif"
    }, 
    "zeroline": True, 
    "autorange": True, 
    "gridcolor": "#eee", 
    "gridwidth": 1, 
    "linecolor": "rgba(152, 0, 0, 0.5)", 
    "linewidth": 1.5, 
    "rangemode": "normal", 
    "tickangle": "auto", 
    "tickcolor": "rgba(0, 0, 0, 0)", 
    "titlefont": {
      "size": 14, 
      "color": "#444", 
      "family": "\"Open sans\", verdana, arial, sans-serif"
    }, 
    "showexponent": "all", 
    "zerolinecolor": "#444", 
    "zerolinewidth": 1, 
    "exponentformat": "B", 
    "showticklabels": True
  }, 
  "bargap": 0, 
  "height": 447, 
  "legend": {
    "x": 0.4805491990846682, 
    "y": 0.8651685393258427, 
    "font": {"color": "rgb(105, 100, 124)"}, 
    "xref": "paper", 
    "yref": "paper", 
    "bgcolor": "white", 
    "bordercolor": "black", 
    "borderwidth": 0
  }, 
  "barmode": "stack", 
  "barnorm": "", 
  "autosize": True, 
  "dragmode": "zoom", 
  "hovermode": "x", 
  "titlefont": {
    "size": 17, 
    "color": "#444", 
    "family": "\"Open sans\", verdana, arial, sans-serif"
  }, 
  "separators": ".,", 
  "showlegend": True, 
  "bargroupgap": 0, 
  "hidesources": False, 
  "plot_bgcolor": "#fff", 
  "paper_bgcolor": "#fff"
}
fig = Figure(data=data, layout=layout)
plot_url = py.plot(fig)