zero_shubham1

mpl_to_plotly

Nov 11th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.59 KB | None | 0 0
  1.  
  2. # coding: utf-8
  3.  
  4. # In[1]:
  5.  
  6.  
  7. from scipy.stats import sem
  8. import pandas as pd
  9. import matplotlib.pyplot as plt
  10. get_ipython().run_line_magic('matplotlib', 'inline')
  11.  
  12.  
  13. # In[2]:
  14.  
  15.  
  16. df = pd.read_csv("remittance-inflow.csv")
  17.  
  18.  
  19. # In[3]:
  20.  
  21.  
  22. df.head()
  23.  
  24.  
  25. # In[4]:
  26.  
  27.  
  28. india_data = df[df["Migrant remittance inflows (US$ million)"] == 'India']
  29.  
  30.  
  31. # In[5]:
  32.  
  33.  
  34. india_data = india_data.fillna(1)
  35.  
  36.  
  37. # In[6]:
  38.  
  39.  
  40. india_data["1970"]
  41.  
  42.  
  43. # In[7]:
  44.  
  45.  
  46. india_data.loc[:"1970"]
  47.  
  48.  
  49. # In[8]:
  50.  
  51.  
  52. col_list = india_data.columns[2:]
  53.  
  54.  
  55. # In[9]:
  56.  
  57.  
  58. india_data[col_list].iloc[0]
  59.  
  60.  
  61. # In[10]:
  62.  
  63.  
  64. india_data_s = india_data[col_list].iloc[0]
  65.  
  66.  
  67. # In[99]:
  68.  
  69.  
  70. x = india_data_s.index
  71.  
  72. x = x[:47]
  73. x
  74.  
  75.  
  76. # In[101]:
  77.  
  78.  
  79. y = india_data_s.values
  80. y = y[:47]
  81.  
  82.  
  83. # In[102]:
  84.  
  85.  
  86. x=x.astype('float64',copy=False)
  87. y=y.astype('float64',copy=False)
  88.  
  89.  
  90. # In[103]:
  91.  
  92.  
  93. plt.plot(x,y)
  94.  
  95.  
  96. # In[104]:
  97.  
  98.  
  99. x
  100.  
  101.  
  102. # In[105]:
  103.  
  104.  
  105. india_data_s.rolling(window=5).mean()[:47].index
  106. x= india_data_s.rolling(window=2).mean()[:47].index
  107. y= india_data_s.rolling(window=2).mean()[:47].values
  108.  
  109.  
  110. # In[107]:
  111.  
  112.  
  113.  
  114. fig = plt.figure(figsize=(14,8))
  115. ax = plt.subplot(111)
  116.  
  117. plt.plot(x,y)
  118. plt.xlim(1970,2016)
  119. plt.ylim(0,75000)
  120. t = plt.xticks(x,x,rotation='vertical',fontsize=12)
  121. plt.fill_between(x,y+5000,y-5000,color='#3F5D7D')
  122. plt.plot(x,y,color='white',lw=2)
  123.  
  124.  
  125. # In[108]:
  126.  
  127.  
  128. import plotly as pltly
  129.  
  130.  
  131. # In[109]:
  132.  
  133.  
  134. pltly.tools.set_credentials_file(username='zero_0',api_key='iTLrjreGKQBYDFnTpQgz')
  135.  
  136.  
  137. # In[110]:
  138.  
  139.  
  140. import plotly.tools as tls
  141.  
  142.  
  143. # In[111]:
  144.  
  145.  
  146. pltly_fig  = tls.mpl_to_plotly(fig)
Add Comment
Please, Sign In to add comment