SHARE
TWEET

Untitled

a guest May 15th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def plot_coins_capitalizations(coins, symbols, start_date):
  2.     required = pd.DataFrame(
  3.     data = coins[(coins['symbol'].isin(symbols)) & (coins['date'] >= start_date)]
  4.     )
  5.     fig = plt.figure(
  6.         figsize=(8, 9),  
  7.         facecolor='white',  
  8.         dpi=200
  9.     )
  10.     plot1 = fig.add_subplot(211)
  11.        
  12.     sum_symbol_market = pd.DataFrame({'sum_market': pd.Series(required.groupby('date')['market'].agg(sum), index = required['date'])})
  13.     plot1.plot(
  14.         pd.to_datetime(sum_symbol_market.index), sum_symbol_market['sum_market'],
  15.         color='red',
  16.         linewidth=1
  17.     )
  18.     plot1.set_ylabel('Market')
  19.     plot1.set_xlabel('Date')
  20.     plot1.grid(True)
  21.    
  22.     sum_market = pd.Series(data = coins.groupby('date')['market'].agg(sum), index = coins['date'])
  23.     required['sum_market'] = required.apply(lambda row: (sum_market[row['date']].values[0]), axis = 1)
  24.     plot2 = fig.add_subplot(212)
  25.     col = 0.1
  26.     for symbol in symbols:
  27.         symbol_data = required[required['symbol'] == symbol]
  28.         plot2.plot(
  29.             pd.to_datetime(symbol_data['date']), symbol_data['market']/symbol_data['sum_market'],
  30.             color=(col, 0, 0),  
  31.             linewidth=1,
  32.             label=symbol
  33.         )
  34.         col += 0.9/len(symbols)
  35.     plot2.set_ylabel('Percentage')
  36.     plot2.set_xlabel('Date')
  37.     plot2.grid(True)
  38.     plot2.legend(
  39.         loc='lower left',
  40.         borderaxespad=1  
  41.     )
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top