python数据处理——堆积面积图

文本数据:横坐标为时间,纵坐标为情感值。代码如下所示:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import pandas as pd
from pylab import mpl
mpl.rcParams['font.sans-serif'] = ['SimHei']   # 设置字体为黑体
mpl.rcParams['axes.unicode_minus'] = False     # 解决中文字体负号显示不正常问题

year=['2019-12-01', '2019-12-02', '2019-12-03', '2019-12-04', '2019-12-05', '2019-12-06', '2019-12-07', '2019-12-08', '2019-12-09', '2019-12-10', '2019-12-11', '2019-12-12', '2019-12-13', '2019-12-14', '2019-12-15', '2019-12-16', '2019-12-17', '2019-12-18', '2019-12-19', '2019-12-20', '2019-12-21', '2019-12-22', '2019-12-23', '2019-12-24', '2019-12-25', '2019-12-26', '2019-12-27', '2019-12-28', '2019-12-29', '2019-12-30', '2019-12-31']

population_by_continent={

    '微博评论情感值':[0.015961569, 0.204441201, 0.443367736, 0.078086815, 0.651858888, 0.858426005, 0.245235327, 0.521995593, 0.006129463, 0.013643959, 0.84333408, 0.731408827, 0.666699209, 0.002177434, 0.000255063, 0.002628827, 0.933298836, 0.489233485, 0.489434259, 1.000612182, 0.691969744, 0.255336003, 0.282948457, 0.489385457, 0.997402575, 0.767176063, 0.563007327, 0.853250709, 0.973132742, 0.714409561, 1.000503621],
    '消费评论情感值':[0.992460962, 1.001026694, 0.000246051, 0.767696571, 0.665908088, 1.000920939, 0.9254107, 1.000632046, 0.969819406, 0.246051727, 1.001124763, 0.20122589, 0.62307711, 1.001051514, 1.001108643, 1.000943001, 1.001304133, 7.51e-06, 1.001321759, 1.001171742, 1.001133869, 0.001651461, 0.785146179, 0.582515799, 0.294841239, 0.938351463, 0.000184873, 0.99791843, 0.986163138, 0.312308209,0.6839862]
}

fig, ax = plt.subplots(1,1,figsize=(8,6), dpi= 80) #设置图片大小

ax.stackplot(year,population_by_continent.values(),
             labels=population_by_continent.keys(),alpha=0.8,colors=['#000000', '#008B00'] )

ax.legend(loc='upper left')
ax.set_title('微博评论情感值与消费评论情感值变化图',)
ax.set_xlabel('日期')
ax.set_ylabel('评论情感值')
plt.gca().xaxis.set_major_locator(ticker.MultipleLocator(31))#31可以改为你需要的时间单位
plt.show()

结果如图下所示:

  • 3
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值