# Colors for the bar plot COLORS = ['orange', 'green', 'orange', 'cyan', 'cyan', 'blue', 'silver', 'orange', 'red', 'green']
# Plotting market_cap_usd as before but adding the colors and scaling the y-axis ax = cap10.market_cap_perc.plot.bar(title='Top 10 market capitalization',color=COLORS)
# Annotating the y axis with 'USD' ax.set_ylabel('USD')
# Final touch! Removing the xlabel as it is not very informative ax.set_xlabel('')
#Defining a function with 2 parameters, the series to plot and the title def top10_subplot(volatility_series, title): # Making the subplot and the figure for two side by side plots fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(10, 6)) # Plotting with pandas the barchart for the top 10 losers ax = volatility_series[:10].plot.bar(color='darkred',ax=axes[0]) # Setting the figure's main title to the text passed as parameter fig.suptitle(title) # Setting the ylabel to '% change' ax.set_ylabel('% change') # Same as above, but for the top 10 winners ax = volatility_series[-10:].plot.bar(color='darkblue',ax=axes[1]) # Returning this for good practice, might use later return fig, ax
DTITLE = "24 hours top losers and winners"
# Calling the function above with the 24 hours period series and title DTITLE fig, ax = top10_subplot(volatility.percent_change_24h,'24 hours top losers and winners')
输出:
24小时百分之800的收益?为什么你还在看这篇文章不赶快去买比特币!(开玩笑😝)
我们再来看看周收益吧:
1 2 3 4 5 6 7
# Sorting in ascending order volatility7d = volatility.sort_values(by='percent_change_7d')
WTITLE = "Weekly top losers and winners"
# Calling the top10_subplot function fig, ax = top10_subplot(volatility7d.percent_change_7d,WTITLE)
Large cap: +10 billion Mid cap: 2 billion - 10 billion Small cap: 300 million - 2 billion Micro cap: 50 million - 300 million Nano cap: Below 50 million
我们来看一下大于一百亿市值的:
1 2 3 4 5
# Selecting everything bigger than 10 billion largecaps = cap.query('market_cap_usd>10000000000')
# Making a nice function for counting different marketcaps from the # "cap" DataFrame. Returns an int. # INSTRUCTORS NOTE: Since you made it to the end, consider it a gift :D def capcount(query_string): return cap.query(query_string).count().id
# Labels for the plot LABELS = ["biggish", "micro", "nano"]
# Using capcount count the biggish cryptos biggish = capcount('market_cap_usd>3000000000')
# Same as above for micro ... micro = capcount('market_cap_usd>50000000 and market_cap_usd<300000000')
# ... and for nano nano = capcount('market_cap_usd<50000000')
# Making a list with the 3 counts values = [biggish,micro,nano]
# Plotting them with matplotlib plt.bar(range(len(values)),values,label=LABELS)