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()
数据文件: