How to Resize Bar Graphs in Python

To make a bar chart larger, you can adjust both the width and height of the bars. When creating a bar chart using the matplotlib library, you can adjust the size of the bars by setting parameters.

Here is a sample code demonstrating how to make a bar chart larger by adjusting its width and height.

import matplotlib.pyplot as plt

# 数据
x = [1, 2, 3, 4, 5]
y = [10, 20, 15, 25, 30]

# 绘制柱状图
plt.bar(x, y, width=0.8)  # 设置柱状图的宽度

# 调整柱状图的大小
plt.gcf().set_size_inches(10, 6)  # 设置图形的尺寸

plt.show()

In the example above, we adjusted the width of the bar graph by setting it to 0.8, and set the size of the entire graph to 10×6 using plt.gcf().set_size_inches(10, 6). You can modify these parameters as needed to change the size of the bar graph.

bannerAds