matpltlib python

1、指定字体,解决中文无法显示
plt.rcParams['font.sans-serif'] = ['SimHei']


# 子图和x轴旋转
fig = plt.figure()

ax1 = fig.add_subplot(2, 1, 1)
ax2 = fig.add_subplot(2, 1, 2)
# 添加标题
ax1.set_title('情绪指数')
ax2.set_title('分歧指数')

# ax1.grid(color='r', linestyle='--', linewidth=1,alpha=0.3)
ax1.plot(x_split_list, y_mood_list)
# 获取每个横坐标,并且旋转45度
for tick in ax1.get_xticklabels():
    tick.set_rotation(45)


ax2.plot(x_split_list, y_disagree_list)
plt.xticks(rotation=45)
plt.show()
print("日期", day_list)
print("情绪指数",y_mood_list)
print("分歧指数",y_disagree_list)



# 删除制定列
del df["标题"]

# 获取某一列的值
data = df.ix[:, ['发帖内容']].values

# 统计发帖的次数
df.groupby('发帖内容')['发帖内容'].count()

# 获取长度
df['发帖内容'].str.len()

# 统计字体的长度
df.groupby('length').count()

# 转列表
len_df.index.tolist()

# 9、绘制句子长度及频次统计

# 绘制句子长度及出现频数统计图
# plt.bar(sent_length, sent_freq)
# plt.title("句子长度及出现频数统计图", fontproperties=my_font)

# plt.title("句子长度及出现频数统计图")
# plt.xlabel("句子长度")
# plt.ylabel("句子长度出现的频数")
# plt.show()
# plt.savefig("./句子长度及出现频数统计图.png")
# plt.close()



# 10、绘制累计的分布函数

# 绘制句子长度累积分布函数(CDF)
sent_pentage_list = [(count / sum(sent_freq)) for count in accumulate(sent_freq)]
#
# 绘制CDF
plt.plot(sent_length, sent_pentage_list)
#
# 寻找分位点为quantile的句子长度
quantile = 0.91
# print(list(sent_pentage_list))
for length, per in zip(sent_length, sent_pentage_list):
    if round(per, 2) == quantile:
        index = length
        break
print("\n分位点为%s的句子长度:%d." % (quantile, index))
#
# # 绘制句子长度累积分布函数图
plt.plot(sent_length, sent_pentage_list)
plt.hlines(quantile, 0, index, colors="c", linestyles="dashed")
plt.vlines(index, 0, quantile, colors="c", linestyles="dashed")
plt.text(0, quantile, str(quantile))
plt.text(index, 0, str(index))
plt.title("句子长度累积分布函数图")
plt.xlabel("句子长度")
plt.ylabel("句子长度累积频率")

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值