Skip to content Skip to sidebar Skip to footer

Too Much Space Between Bars In Matplotlib Bar Chart

I am trying to create a bar chart with matplotlib. The x-axis data is a list with years: [1950,1960,1970,1980,1990,1995-2015] The y-axis data is a list with equal amount of numbers

Solution 1:

You need to plot the population data as a function of increasing integers. This makes the bars have equal spacings. You can then adapt the labels to be the years that each graph represents.

import matplotlib.pyplot as plt
import numpy as np

jahre = np.append(np.arange(1950,2000,10), np.arange(1995,2017))
bevoelkerung = np.cumsum(np.ones_like(jahre))
x = np.arange(len(jahre))

plt.bar(x, bevoelkerung)
plt.xticks(x, jahre, rotation=90)
plt.show()

enter image description here

Post a Comment for "Too Much Space Between Bars In Matplotlib Bar Chart"