感谢chatgpt
import matplotlib.pyplot as plt
# Define the data for the two columns
column1 = [1, 2, 3, 4, 5]
column2 = [2, 4, 6, 8, 10]
# Define the x-axis labels
x_labels = [0, 1, 2, 3, 4]
# Plot the two columns of data as a bar chart
fig, ax = plt.subplots()
ax.bar(x_labels, column1, label='Column 1')
ax.bar(x_labels, column2, label='Column 2', bottom=column1)
# Add a legend and labels for the x and y axes
ax.legend()
ax.set_xlabel('X Value')
ax.set_ylabel('Y Value')
# Set the limits of the x and y axes to start at 0
ax.set_xlim(0, max(x_labels))
ax.set_ylim(0, max(column1 + column2))
# Display the bar chart
plt.show()
在上面的代码中,我们定义了两个数列的数据,并定义了 x 轴的标签。然后,我们使用 Matplotlib 库绘制双列柱状图,并在图上添加标题、图例、坐标轴标签。最后,我们使用 ax.set_xlim(0, max(x_labels)) 和 ax.set_ylim(0, max(column1 + column2)) 函数设置 x 轴和 y 轴的范围,从而确保图形从原点开始画。最后,我们使用 plt.show() 函数显示图形。