1

I've created the following bar chart that is a composite of a few different research areas:

enter image description here

There are gaps between the columns as a result of the '0' entries for each decade, however, I'd like to be able to group the columns together within the decades to effectively remove these gaps and neaten it up, I have tried a few things but I am really new to this and I can't seem to make it work, this is my code for the graph:

import numpy as np
import matplotlib.pyplot as plt

# data to plot
n_groups = 6
Ecological_effects = (0,1,0,2,2,9)
Hydrological = (0,0,0,1,0,2)
Engineering_properties = (1,0,2,0,2,3)
Stochastic_events = (0,0,0,0,0,3)
Microbiological_effects = (0,0,0,0,0,3)
Emissions = (0,0,0,0,0,4)
Erosion = (0,0,0,0,0,1)
Other = (0,0,0,1,0,1)

# create plot
fig, ax = plt.subplots()
index = np.arange(n_groups)
bar_width = 0.1
opacity = 1

rects1 = plt.bar(index, Ecological_effects, bar_width,
alpha=opacity,
color= 'mediumorchid',
label='Ecological effects')

rects2 = plt.bar(index + bar_width, Hydrological, bar_width,
alpha=opacity,
color='forestgreen',
label='Hydrological effects')

rects3 = plt.bar(index + bar_width*2, Engineering_properties, bar_width,
alpha=opacity,
color='coral',
label='Engineering properties')

rects4 = plt.bar(index + bar_width*3, Stochastic_events, bar_width,
alpha=opacity,
color='deepskyblue',
label='Stochastic events')

rects5 = plt.bar(index + bar_width*4, Microbiological_effects, bar_width,
alpha=opacity,
color='goldenrod',
label='Microbiological effects')

rects6 = plt.bar(index + bar_width*5, Emissions, bar_width,
alpha=opacity,
color='mediumspringgreen',
label='Emissions')

rects7 = plt.bar(index + bar_width*6, Erosion , bar_width,
alpha=opacity,
color='darkred',
label='Erosion and compaction processes')

rects8 = plt.bar(index + bar_width*7, Other, bar_width,
alpha=opacity,
color='chartreuse',
label='Other')


plt.xlabel('Decade')
plt.ylabel('Number of publications')
plt.title('Publications')
plt.xticks(index + bar_width, ('Pre-1970s', '1970-1979', '1980-1989', '1990-1999', '2000-2009', '2010-present'))
plt.legend()


plt.tight_layout()
plt.show()

All help greatly appreciated!

Zephyr
  • 11,891
  • 53
  • 45
  • 80

0 Answers0