I am trying to plot a stacked line graph to show the distribution of different categories per day, over time:
dates = [datetime.date(2023, 1, 1), datetime.date(2023, 1, 1), .. ]
instance_data = [80.0739, 0.9492, 0.9492], [46.2961, 0.0, 0.0], .. ]
ax.stackplot(dates, instance_data, labels=labels)
But am getting the following error due to a mismatch in the shapes of the arrays dates
and instance_data
:
ValueError: operands could not be broadcast together with shapes (95,) (3,)
How would I be able to resolve this? The data I am processing comes in the format:
- List of tuples
- Each tuple contains: date, instance type, value 1, value 2, value
[(datetime.date(2023, 1, 1), 'c5d.18xlarge', Decimal('0.0000'), Decimal('0.0000'), Decimal('310.3294')), (datetime.date(2023, 1, 1), 'c5d.2xlarge', Decimal('28.7031'), Decimal('0.0000'), Decimal('24.5456')), (datetime.date(2023, 1, 1), 'c5d.4xlarge', Decimal('18.9289'), Decimal('0.0000'), Decimal('3.4653')), (datetime.date(2023, 1, 1), 'c5d.9xlarge', Decimal('6.8633'), Decimal('0.0000'), Decimal('198.9642')), (datetime.date(2023, 1, 1), 'm5d.2xlarge', Decimal('21.3989'), Decimal('0.0000'), Decimal('0.0000')), (datetime.date(2023, 1, 1), 'm5d.4xlarge', Decimal('11.9900'), Decimal('0.0000'), Decimal('0.0000')), (datetime.date(2023, 1, 2), 'c5d.18xlarge', Decimal('0.3150'), Decimal('0.0000'), Decimal('10.6647')), ... ]
I tried changing the shape of the dates
list to match that of the instance_data
list (95, 3):
# datetime.object is arbitrary for this example
dates = [[datetime.object, datetime.object, datetime.object] for i in range(len(instance_data))]
but then got the error:
`TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''`