# Get this figure: fig = py.get_figure("https://chart-studio.plotly.com/~mmester/101/")
# Get this figure's data: data = py.get_figure("https://chart-studio.plotly.com/~mmester/101/").get_data()
# Add data to this figure: py.plot(Data([Scatter(x=[1, 2], y=[2, 3])]), filename ="U.S. alcohol expenditure", fileopt="extend")
# Get y data of first trace: y1 = py.get_figure("https://chart-studio.plotly.com/~mmester/101/").get_data()[0]["y"]

# 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": "a523ba", 
  "name": "Alcohol expenditure (% of after-tax income)", 
  "type": "scatter", 
  "xsrc": "mmester:98:a97151", 
  "x": ["1984", "1985", "1986", "1987", "1988", "1989", "1990", "1991", "1992", "1993", "1994", "1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014"], 
  "ysrc": "mmester:98:3c5efc", 
  "y": ["1.29%", "1.34%", "1.17%", "1.16%", "1.03%", "1.00%", "1.01%", "0.97%", "0.98%", "0.84%", "0.84%", "0.82%", "0.89%", "0.84%", "0.81%", "0.78%", "0.90%", "0.78%", "0.80%", "0.80%", "0.88%", "0.76%", "0.86%", "0.75%", "0.72%", "0.72%", "0.68%", "0.74%", "0.71%", "0.79%", "0.79%"]
}
trace2 = {
  "uid": "f0ca73", 
  "fill": "tozeroy", 
  "line": {
    "shape": "hvh", 
    "width": 0
  }, 
  "mode": "lines", 
  "name": "Recessions", 
  "type": "scatter", 
  "xsrc": "mmester:98:7fda7c", 
  "x": ["1984", "1985", "1986", "1987", "1988", "1989", "1990.583", "1991.25", "1991.3", "1993", "1994", "1995", "1996", "1997", "1998", "1999", "2000", "2001.25", "2001.92", "2002", "2004", "2005", "2006", "2007.95", "2008", "2009.5", "2009.55", "2011", "2012", "2013", "2014"], 
  "ysrc": "mmester:98:e6a036", 
  "y": ["0%", "0%", "0%", "0%", "0%", "0%", "1.5%", "1.5%", "0%", "0%", "0%", "0%", "0%", "0%", "0%", "0%", "0%", "1.5%", "1.5%", "0%", "0%", "0%", "0%", "1.5%", "1.5%", "1.5%", "0%", "0%", "0%", "0%", "0%"], 
  "visible": True, 
  "fillcolor": "rgba(204, 204, 204, 0.5)", 
  "hoverinfo": "none", 
  "showlegend": False
}
data = Data([trace1, trace2])
layout = {
  "title": "U.S. consumer alcohol spending has<br>gradually declined since mid-1980s", 
  "width": 800, 
  "xaxis": {
    "type": "linear", 
    "range": [1984, 2014], 
    "title": "", 
    "autorange": True, 
    "tickformat": "", 
    "ticksuffix": ""
  }, 
  "yaxis": {
    "range": [0, 1.5789473684210527], 
    "title": "Household alcohol spend (% of after-tax income)", 
    "autorange": True, 
    "tickformat": "", 
    "ticksuffix": "%", 
    "exponentformat": "B"
  }, 
  "height": 560, 
  "autosize": False, 
  "showlegend": False, 
  "annotations": [
    {
      "x": 0, 
      "y": -0.2, 
      "font": {"color": "rgb(102, 102, 102)"}, 
      "text": "Note: Shaded ares denote recessions<br>Source: BLS CES, NBER", 
      "xref": "paper", 
      "yref": "paper", 
      "align": "left", 
      "xanchor": "left", 
      "yanchor": "bottom", 
      "showarrow": False
    }
  ], 
  "hidesources": True
}
fig = Figure(data=data, layout=layout)
plot_url = py.plot(fig)