I have the following Data Frame :
Location Growth Growth_Zero_Migration
0 Africa 2939529.018 2998261.337
1 Asia 78852.134 256394.122
2 Australia/New Zealand 18563.010 -2212.990
3 Europe and Northern America 3945.429 -253849.105
4 South America -1459.056 3117.976
When I try to display it by matplot (as a grouped bar chart ),not all the negative values are shown correctly.I found this solution Negative values bars on the same matplotlib chart , but it didn't help me a lot - all my bars get either bottom or top value of y .I guess my problem is a range ( as you can see it's [-253849.105, 2998261.337], but I've no idea how to normalize it . Any hint will be very appreciated. Here is my code and output :
..........
def get_Table_For_Growth(columnName, fileName, variant, range):
pop_stat = pb.read_csv("WPP2019_TotalPopulationBySex.csv")
locations_table = pb.read_csv("{filename}.csv".format(filename=fileName))
table = pop_stat[(pop_stat['Variant'] == variant) & (pop_stat[columnName].isin(locations_table[columnName])) & (
(pop_stat['Time'] == range[0]) | (pop_stat['Time'] == range[1]))].loc[:, ['Location', 'PopTotal']]
table['Growth'] = table.groupby('Location')['PopTotal'].diff()
table = table.dropna()
table = table.reset_index(drop=True)
# table.style.hide_index()
table = table.sort_values(by='Growth', ascending=False)
del table['PopTotal']
return table
def show_graph(table, type, xcoor, ycoor, colour):
table.plot(kind=type, x=xcoor, y=ycoor, color=colour)
plt.show()
continents_zero_migration = get_Table_For_Growth("Location", "continents", "Zero migration", [2020, 2100])
continents_medium_vs_zero_migration = get_Table_For_Growth("Location", "continents", "Medium", [2020, 2100])
continents_medium_vs_zero_migration['Growth_Zero_Migration'] = continents_zero_migration['Growth']
continents_medium_vs_zero_migration = pb.DataFrame({'Growth Forecast': continents_medium_vs_zero_migration['Growth'].tolist(),
'Zero migration' : continents_medium_vs_zero_migration['Growth_Zero_Migration'].tolist()},
index = continents_medium_vs_zero_migration['Location'])
continents_medium_vs_zero_migration.plot.bar()
plt.show()
..........


