python折线图、柱状图、百分比图

import numpy as np
import pandas as pd
from pyecharts.charts import *
import pyecharts.options as opts
from matplotlib.font_manager import FontProperties
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter
plt.rcParams["font.sans-serif"]=["SimHei"]
plt.rcParams["figure.figsize"] = (4,3)
x=[4,5,6,7,8]
y=[10095,11108,12361,13022,13654]
figure,axes=plt.subplots()
axes.set_title('共识节点规模-总耗时关系图')
axes.plot(x,y,marker="^",markeredgecolor='r',markersize='5',markeredgewidth=1.5)
axes.set_ylabel('总耗时(ms)')
axes.set_xlabel('共识节点规模')
plt.savefig('共识节点规模-总耗时关系图.svg', bbox_inches='tight',format='svg')
plt.show()

在这里插入图片描述

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd


def add_text(x, y, data, fontsize=12):
    for x0, y0, data0 in zip(x, y, data):
        axs[1].text(x0, y0, round(data0, 1), rotation=90)

csv = pd.read_csv(r'C:\Users\LiJie\Desktop\salary.csv')
name = csv.node
salary1 = np.array(csv.n1)
salary2 = np.array(csv.n2)
salary3 = np.array(csv.n3)
index = np.arange(len(name))
width = 0.4

fig, axs = plt.subplots(1, 2, figsize=(10, 5))

axs[0].bar(index, salary1, width=width, label='生成')
axs[0].bar(index, salary2, width=width, bottom=salary1, label='验证')
axs[0].bar(index, salary3, width=width, bottom=salary2 + salary1, label='选择、记录')
axs[0].set_ylim(0, 30000)
axs[0].set_xticks(index)
axs[0].set_xticklabels(name, rotation=90)
axs[0].legend(loc='upper left', shadow=True)

sum = salary1 + salary2 + salary3
percentage1 = salary1 / sum
percentage2 = salary2 / sum
percentage3 = salary3 / sum

axs[1].bar(index, percentage1, width=width, label='生成')
axs[1].bar(index, percentage2, width=width, bottom=percentage1, label='验证')
axs[1].bar(index, percentage3, width=width,
           bottom=percentage1 + percentage2, label='选择、记录')
axs[1].set_ylim(0, 1)
axs[1].set_xticks(index)
axs[1].set_xticklabels(name, rotation=90)

y1 = percentage1/2
y2 = percentage1 + percentage2/2
y3 = sum - percentage3/2

# add_text(index-width/2, y1, percentage1)
# add_text(index-width/2, y2, percentage2)
# add_text(index-width/2, y3, percentage3)
def to_percent(temp, position):
    return '%1.0f'%(100*temp) + '%'
plt.gca().yaxis.set_major_formatter(FuncFormatter(to_percent))

axs[0].set_xlabel('共识节点规模')
axs[0].set_ylabel('耗时(ms)')
plt.ylabel('百分比(%)')
plt.xlabel('共识节点规模')
plt.savefig('9.tiff', dpi=300)
plt.show()

在这里插入图片描述
数据文件:
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yitahutu79

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值