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 as in years.
This is my code:
import csv
import matplotlib.pyplot as plt
path = "bevoelkerung_entwicklung.csv"
with open(path, 'r') as datei:
reader = csv.reader(datei, delimiter=';')
jahr = next(reader)
population = next(reader)
population_list = []
for p in population:
population_list.append(str(p).replace("'",""))
population_list = list(map(int, population_list))
jahr = list(map(int, jahr))
datei.close()
plt.bar(jahr,population_list, color='c')
plt.xlabel('Year')
plt.ylabel('Population in 1000')
plt.title('Population growth')
plt.legend()
plt.show()
And the outcome is the following: Too much space between bars
As you can see the gaps between 1950-1960 is huge. How can I make it, so that there is no gap inbetween the bars 1950-1995. I get that it has intervals of 10 years, but it doesn't look good.
Any help would be appreaciated.
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.