参考記事の応用で、自作EAの通貨別稼働数をPythonで表示してみました。
棒の上に数値を表示する方法を解説しています。
結果

実際に書いたコード
import matplotlib.pyplot as plt
plt.rcParams["font.family"] = "Meiryo"
fig, ax = plt.subplots()
fig.canvas.manager.set_window_title("自作EA稼働数")
labels = ["ポンド円", "ドル円", "オージー円"]
data = [9, 6 + 8 + 10, 3]
bars = ax.bar(labels, data)
ax.set_title("2026-02-21 通貨ペア別稼働数")
ax.set_xlabel("")
ax.set_ylabel("稼働数")
ax.grid(False)
# 棒の上に数値を表示
for bar in bars:
height = bar.get_height()
ax.text(
bar.get_x() + bar.get_width() / 2, # 棒の中央
height, # 棒の高さ(上端)
str(height), # 表示する文字
ha="center", # 中央揃え
va="bottom", # 下端揃え
)
plt.show()
棒の上に数値を表示する方法を解説
ax.bar(labels, data) の前に bars = を追加して
bars = ax.bar(labels, data)
棒の上に数値を表示
# 棒の上に数値を表示
for bar in bars:
height = bar.get_height()
ax.text(
bar.get_x() + bar.get_width() / 2, # 棒の中央
height, # 棒の高さ(上端)
str(height), # 表示する文字
ha="center", # 中央揃え
va="bottom", # 下端揃え
)




人気ブログランキング ブログパーツ