300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 【python 作日期的折线图和柱状图组合图】

【python 作日期的折线图和柱状图组合图】

时间:2019-06-29 00:21:04

相关推荐

【python 作日期的折线图和柱状图组合图】

在这里插入代码片``###法一:但是没有标数据import matplotlibimport matplotlib.pyplot as pltmatplotlib.rcParams['font.sans-serif'] = ['SimHei'] # 用黑体显示中文import pandas as pdimport matplotlib.pyplot as pltexample = {'Timestamp':['-10', '-11', '-12', '-01', '-02', '-03','-04', '-05', '-06', '-07', '-08','-09','-10'], '数':[7,178, 437, 280, 204,249,844,475,468,264,490,822,561]}df = pd.DataFrame(example)```import seaborn as snsimport matplotlib.pyplot as pltimport pandas as pd#设置格式sns.set_style("whitegrid")x = df['Timestamp']y =df['数']#设置图形大小plt.rcParams['figure.figsize'] = (12.0,5.0)fig = plt.figure()#画柱形图ax1 = fig.add_subplot(111)ax1.bar(x,y,alpha=.7,color='g')ax1.set_ylabel('数',fontsize='15')#ax1.set_title("数据统计",fontsize='20')#画折线图 ax2 = ax1.twinx() #组合图ax2.set_ylabel('',fontsize='15')ax2.plot(x, y, 'r',ms=10)plt.show()###法二有标数据import matplotlibimport matplotlib.pyplot as pltmatplotlib.rcParams['font.sans-serif'] = ['SimHei'] # 用黑体显示中文import pandas as pdimport matplotlib.pyplot as pltexample = {'Timestamp':['-10', '-11', '-12', '-01', '-02', '-03','-04', '-05', '-06', '-07', '-08','-09','-10'], '数':[7,178, 437, 280, 204,249,844,475,468,264,490,822,561]}df = pd.DataFrame(example)x = df['Timestamp']y =df['弹幕数'] plt.bar(x=x, height=y, label='', color='steelblue', alpha=0.8)for x1, yy in zip(x, y):plt.text(x1, yy + 1, str(yy), ha='center', va='bottom', fontsize=10, rotation=0)plt.title("弹幕数随日期活跃度")plt.xlabel("发布日期")plt.ylabel("数量")plt.legend()plt.plot(x, y, "r", marker='*', ms=10, label="a")plt.xticks(rotation=45)plt.legend(loc="upper left")plt.savefig("a.jpg")plt.show()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。