Skip to content

Commit

Permalink
style: fix style
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain committed Feb 19, 2024
1 parent e120feb commit 63b32fe
Showing 1 changed file with 55 additions and 28 deletions.
83 changes: 55 additions & 28 deletions javascript/benchmark/platform-buffer-draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,54 +18,81 @@
import matplotlib.pyplot as plt
import sys

[_, browser_utf8_write, browser_write, browser_write_1, native_write, browser_to_string, native_to_string] = sys.argv[0:7]
[
_,
browser_utf8_write,
browser_write,
browser_write_1,
native_write,
browser_to_string,
native_to_string,
] = sys.argv[0:7]

# 创建图形和子图
fig, axs = plt.subplots(nrows=1, ncols=3, figsize=(15, 5), sharey=True)

# 绘制第一部分比较:browser utf8Write 和 browser write
axs[0].bar(['browser utf8Write', 'browser write'], [browser_utf8_write, browser_write], color=['b', 'g'])
axs[0].set_title('Browser UTF8 Write vs Browser Write')
axs[0].set_xlabel('Operation Type')
axs[0].set_xticklabels(['browser utf8Write', 'browser write'])
axs[0].bar(
["browser utf8Write", "browser write"],
[browser_utf8_write, browser_write],
color=["b", "g"],
)
axs[0].set_title("Browser UTF8 Write vs Browser Write")
axs[0].set_xlabel("Operation Type")
axs[0].set_xticklabels(["browser utf8Write", "browser write"])
axs[0].set_ylabel("Tps")


# 在柱形图上添加数值标签
for p in axs[0].patches:
axs[0].annotate(format(p.get_height(), '.0f'),
(p.get_x() + p.get_width() / 2., p.get_height()),
ha = 'center', va = 'center',
xytext = (0, 9),
textcoords = 'offset points')
axs[0].annotate(
format(p.get_height(), ".0f"),
(p.get_x() + p.get_width() / 2.0, p.get_height()),
ha="center",
va="center",
xytext=(0, 9),
textcoords="offset points",
)

# 绘制第二部分比较:browser write 和 native write
axs[1].bar(['browser write', 'native write'], [browser_write_1, native_write], color=['g', 'r'])
axs[1].set_title('Browser Write vs Native Write')
axs[1].set_xlabel('Operation Type')
axs[1].set_xticklabels(['browser write', 'native write'])
axs[1].bar(
["browser write", "native write"], [browser_write_1, native_write], color=["g", "r"]
)
axs[1].set_title("Browser Write vs Native Write")
axs[1].set_xlabel("Operation Type")
axs[1].set_xticklabels(["browser write", "native write"])

# 在柱形图上添加数值标签
for p in axs[1].patches:
axs[1].annotate(format(p.get_height(), '.0f'),
(p.get_x() + p.get_width() / 2., p.get_height()),
ha = 'center', va = 'center',
xytext = (0, 9),
textcoords = 'offset points')
axs[1].annotate(
format(p.get_height(), ".0f"),
(p.get_x() + p.get_width() / 2.0, p.get_height()),
ha="center",
va="center",
xytext=(0, 9),
textcoords="offset points",
)

# 绘制第三部分比较:browser toString 和 native toString
axs[2].bar(['browser toString', 'native toString'], [browser_to_string, native_to_string], color=['b', 'r'])
axs[2].set_title('Browser ToString vs Native ToString')
axs[2].set_xlabel('Operation Type')
axs[2].set_xticklabels(['browser toString', 'native toString'])
axs[2].bar(
["browser toString", "native toString"],
[browser_to_string, native_to_string],
color=["b", "r"],
)
axs[2].set_title("Browser ToString vs Native ToString")
axs[2].set_xlabel("Operation Type")
axs[2].set_xticklabels(["browser toString", "native toString"])

# 在柱形图上添加数值标签
for p in axs[2].patches:
axs[2].annotate(format(p.get_height(), '.0f'),
(p.get_x() + p.get_width() / 2., p.get_height()),
ha = 'center', va = 'center',
xytext = (0, 9),
textcoords = 'offset points')
axs[2].annotate(
format(p.get_height(), ".0f"),
(p.get_x() + p.get_width() / 2.0, p.get_height()),
ha="center",
va="center",
xytext=(0, 9),
textcoords="offset points",
)

# 调整布局以避免重叠
plt.tight_layout()
Expand Down

0 comments on commit 63b32fe

Please sign in to comment.