October 19, 2024
import matplotlib.pyplot as plt

categories = ['Category A', 'Category B', 'Category C']
values = [10, 15, 7]

fig = plt.figure()
ax1= fig.add_subplot(1, 2, 1)
bars = ax1.bar(categories, values, color='skyblue')
for v, bar in zip(values, bars):
    yval = bar.get_height()
    ax1.text(
        bar.get_x() + bar.get_width()/2,
        yval,
        f'{str(v)}', 
        va='bottom',
        ha='center',
        fontsize=10,
        color='blue'
    )

ax1.grid()
ax1.set_yscale('log')
ax1.set_title('Bar Graph with Value Labels')
ax1.set_xlabel('Categories')
ax1.set_ylabel('Values')

# グラフを表示
plt.show()