双色球一等奖中奖占比率一直徘徊在7%左右
2005-2018年,双色球的数据统计
left:x轴的位置序列,一般采用arange函数产生一个序列;
height:y轴的数值序列,也就是柱形图的高度,一般就是我们需要展示的数据;
alpha:透明度
width:为柱形图的宽度,一般这是为0.8即可;
color或facecolor:柱形图填充的颜色;
edgecolor:图形边缘颜色
label:解释每个图像代表的含义
linewidth or linewidths or lw:边缘or线的宽度
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
def DrawHistogram(read_name):
#读取数据
read_name = r"C:\Users\Administrator\Desktop\ssq.csv"
fp = pd.read_csv(read_name)
first_prize = fp.first_prize
second_prize = fp.second_prize
#配置图形参数
ind = np.arange(len(first_prize))
width = 0.5
fig, ax = plt.subplots()
rects1 = ax.bar(ind - width/2, first_prize, width, color='SkyBlue', label='First')
rects2 = ax.bar(ind + width/2, second_prize, width,color='IndianRed', label='Second')
ax.set_ylabel('Stakes')
ax.set_title('Stakes by year and rank')
plt.xticks(ind,(18,17,16,15,14,13,12,11,10,9,8,7,6,5))
ax.legend()
plt.show()
if __name__=='__main__':
DrawHistogram(r"C:\Users\Administrator\Desktop\ssq.csv")
历年一等奖、二等奖中奖数
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
def DrawBubble(read_name):
#读取数据
fp = pd.read_csv(read_name)
x = fp.sales
y = fp.rate
z = fp.rate
#配置参数
sns.set(style = "whitegrid")
cm = plt.cm.get_cmap('RdYlBu')
fig,ax = plt.subplots(figsize = (12,10))
bubble = ax.scatter(x, y , s = (z - np.min(z) + 0.1) * 3000, c = z, cmap = cm, linewidth = 0.5, alpha = 0.5)
ax.grid()
fig.colorbar(bubble)
ax.set_xlabel('sales of year', fontsize = 15)
ax.set_ylabel('rate of something', fontsize = 15)
plt.show()
if __name__=='__main__':
DrawBubble(r"C:\Users\Administrator\Desktop\ssq.csv")
历年销售额与一等奖的中奖占比率之间关系
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.font_manager
#读取数据
read_name = r"C:\Users\Administrator\Desktop\ssq.csv"
fp = pd.read_csv(read_name)
first_prize = fp.first_prize
second_prize = fp.second_prize
rate = fp.rate
#一等奖中奖注数
S1=first_prize
x1=[(3/2)*np.pi+np.pi/(len(S1)+1)*(i+1) for i in range(2*(len(S1)+1)) if iy1=[180 for i in range(2*(len(S1)+1)) if i
#为了画出效果比例好看,将二等奖注数缩小5倍来表示
S2=second_prize/5
x2=[(3/2)*np.pi+np.pi/(len(S1)+1)*(i+1) for i in range(2*(len(S1)+1)) if iy2=[130 for i in range(2*(len(S1)+1)) if i
H1=[60/2,69/2,70/2,62/2,67/2,70/2,75/2,67/2,70/2,70/2,64/2,74/2,70/2,72/2]
W1=[0.05 for i in range(2*(len(S1)+1)) if iB=[30 for i in range(2*(len(S1)+1)) if i
fig=plt.figure(figsize=(13.44*2,7.5*2),facecolor='w')
#建立一个坐标系,projection='polar'表示极坐标
ax = fig.add_subplot(111,projection='polar',facecolor='w')
ax.scatter(x=x1,y=y1,s=S1,color='Gold',alpha=0.5,linewidths=0)
ax.scatter(x=x2,y=y2,s=S2,color='Orange',alpha=0.5,linewidths=0)
ax.bar(x=x1, height=H1, width=W1,bottom=B,color='Salmon')
plt.ylim(0,220)
#去掉坐标轴的为外面一层粗的线
ax.spines['polar'].set_visible(False)
plt.grid(color='gray', linestyle=':', linewidth=1,which='major',axis='x',alpha=0.1)
ax.set_yticks([])
ax.tick_params(axis='x',labelsize=0)
font=matplotlib.font_manager.FontProperties(fname=r'E:\project\wordcloud\simfang.ttf')
for i in range(len(x1)):
ax.text(x=x1[i],y=y1[i],s=S1[i],color='gray',ha='center', va= 'center',fontsize=12,fontproperties=font)
for i in range(len(x1)):
ax.text(x=x1[i],y=y2[i],s=S2[i],color='gray',ha='center', va= 'center',fontsize=12,fontproperties=font)
for i in range(len(x1)):
ax.text(x=x1[i],y=H1[i]+40,s="{}‰".format(H1[i]*2) ,color='gray',ha='center', va= 'center',fontsize=12,fontproperties=font)
plt.show()
fig.savefig('D:\\test.png',dpi=400,bbox_inches='tight',transparent=False)