Matplotlib stacked area plot is very jagged and not connected

127 Views Asked by At

I've been experimenting with simulating different biological and ecological processes. Right now I'm doing evolution and adaptation and am experimenting with green beard altruism. I am attempting to do a stacked plot so I can see the relationship between the sizes of two groups of organisms. Here is the code:

def plot_results(self):
    plt.stackplot(self.generation_marks, self.num_alts, self.num_alts, labels=['Number of Altruists', 'Number of Cowards'])
    plt.xlabel('Reproductive Generation', fontsize=14)
    plt.ylabel('Number of Cowards and Altruists', fontsize=14)
    plt.xticks(scipy.arange(0, self.generation, 100))
    plt.legend(loc='upper left')
    plt.tight_layout()
    plt.show()

However, it looks very jagged and unconnected:

enter image description here

Sample Data:

X (each generation): [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29]

Y1 (number of altruists): [2, 2, 2, 2, 2, 3, 2, 2, 2, 5, 3, 9, 3, 6, 4, 10, 4, 8, 3, 5, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

y2 (number of cowards) [3, 6, 6, 12, 12, 23, 18, 35, 18, 32, 17, 33, 17, 31, 16, 31, 16, 33, 17, 38, 18, 39, 20, 42, 20, 40, 20, 41, 20, 41, 20, 40, 20, 42, 20, 37, 20, 40, 20, 36, 20, 38, 20, 39, 20, 37, 20, 39, 20, 37, 20, 39, 20, 36, 20, 39, 20, 39, 20, 41]

Does anyone know how to fix this? Thanks!

0

There are 0 best solutions below