Python绘制方向朝下的柱状图简单示例代码
import matplotlib.pyplot as plt
# 示例数据
categories = ['Category A', 'Category B', 'Category C', 'Category D']
values = [20, 15, 10, 25]
# 创建一个新的绘图
fig, ax = plt.subplots()
# 绘制柱状图
ax.bar(categories, values, color='blue')
# 设置标题和标签
ax.set_title('downward bar chart')
ax.set_xlabel('categories')
ax.set_ylabel('value')
# 反转y轴,使柱状图从上到下
ax.invert_yaxis()
# 显示图例
ax.legend(['value'])
# 展示图像
plt.show()