Disclaimer: perhaps my research was lacking, but I didn't find an answer exactly tailored to my question.
I have a set of datasets with specific sizes which were made available in different years. For example, in 2005 we had dataset A (size 500), B (size 100) and C (size 789) and then in 2013 we had dataset H (size 1500), I (size 300) and J (size 47).
I would like to have the size
on the vertical YY axis while the horizontal XX axis would be hierarchical: first ordered by year
and within each year it would be ordered by size
.
Additionally, I would like to display the XX labels as a string formatted as "YYYY dataset_name". For the example above, the XX axis would have the following labels in this order:
2005 B-100
2005 A-500
2005 C-789
2013 J-47
2013 I-300
2013 H-1500
From the examples I found, it is usually assumed that the same elements are present in every group (if that was the case, each dataset name would appear once for each year - but that is not what I want).
Consider this example from The Python Graph Gallery:
# libraries
import numpy as np
import matplotlib.pyplot as plt
# set width of bar
barWidth = 0.25
# set height of bar
bars1 = [12, 30, 1, 8, 22]
bars2 = [28, 6, 16, 5, 10]
bars3 = [29, 3, 24, 25, 17]
# Set position of bar on X axis
r1 = np.arange(len(bars1))
r2 = [x + barWidth for x in r1]
r3 = [x + barWidth for x in r2]
# Make the plot
plt.bar(r1, bars1, color='#7f6d5f', width=barWidth, edgecolor='white', label='var1')
plt.bar(r2, bars2, color='#557f2d', width=barWidth, edgecolor='white', label='var2')
plt.bar(r3, bars3, color='#2d7f5e', width=barWidth, edgecolor='white', label='var3')
# Add xticks on the middle of the group bars
plt.xlabel('group', fontweight='bold')
plt.xticks([r + barWidth for r in range(len(bars1))], ['A', 'B', 'C', 'D', 'E'])
# Create legend & Show graphic
plt.legend()
plt.show()
It produces the following plot:
My plot would be something like this. However, not all variables would be in every category. It would look like this:
The years would appear where the single bold letters are. The text over the years wouldn't necessarily be numbers, they could be the dataset names.
I would need the groups, however, to be equally-spaced as shown.
Any help appreciated.